This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1017 from kolesnikoff/feature/dev-os25
Google Translate block
- Loading branch information
Showing
21 changed files
with
533 additions
and
18 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
modules/custom/openy_gtranslate/config/optional/block.block.openy_lily_googletranslate.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
uuid: 5a698466-f499-4dda-a084-4d61c1d0e777 | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- openy_gtranslate | ||
theme: | ||
- openy_lily | ||
id: openy_lily_googletranslate | ||
theme: openy_lily | ||
region: secondary_menu | ||
weight: 49 | ||
provider: null | ||
plugin: openy_gtranslate_block | ||
settings: | ||
id: openy_gtranslate_block | ||
label: 'OpenY Google Translate' | ||
provider: openy_gtranslate | ||
label_display: '0' | ||
visibility: { } |
20 changes: 20 additions & 0 deletions
20
modules/custom/openy_gtranslate/config/optional/block.block.openy_rose_googletranslate.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
uuid: 5a698466-f499-4dda-a084-4d61c1d0e902 | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- openy_gtranslate | ||
theme: | ||
- openy_rose | ||
id: openy_rose_googletranslate | ||
theme: openy_rose | ||
region: secondary_menu | ||
weight: 49 | ||
provider: null | ||
plugin: openy_gtranslate_block | ||
settings: | ||
id: openy_gtranslate_block | ||
label: 'OpenY Google Translate' | ||
provider: openy_gtranslate | ||
label_display: '0' | ||
visibility: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(function ($) { | ||
|
||
Drupal.behaviors.openy_gtranslate = { | ||
attach: function (context, settings) { | ||
setTimeout(function () { | ||
var langSelect = $('.goog-te-menu-frame').first(); | ||
|
||
$('nav .navbar-nav li.language > a').on('click', function (e, context) { | ||
e.preventDefault(); | ||
langSelect.show(); | ||
langSelect.addClass('open'); | ||
return false; | ||
}); | ||
|
||
$('body').on('click', function (e, context) { | ||
if (langSelect.hasClass('open')) { | ||
langSelect.hide(); | ||
langSelect.removeClass('open'); | ||
} | ||
}); | ||
}, 100); | ||
} | ||
}; | ||
|
||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: OpenY Google Translate | ||
type: module | ||
description: OpenY module for Google Translate integration. | ||
core: 8.x | ||
version: 8.0.1 | ||
package: OpenY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Installation file for OpenY Google Translate module. | ||
*/ | ||
|
||
use Drupal\menu_link_content\Entity\MenuLinkContent; | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function openy_gtranslate_install() { | ||
$config = \Drupal::config('system.theme'); | ||
$menuName = ($config->get('default') == 'openy_rose') ? 'account' : 'main'; | ||
$menuLink = MenuLinkContent::create([ | ||
'title' => t('Language'), | ||
'link' => [ | ||
'uri' => 'internal:/', | ||
'options' => [ | ||
'attributes' => [ | ||
'class' => ['language hidden-md hidden-lg'], | ||
], | ||
], | ||
], | ||
'menu_name' => $menuName, | ||
'weight' => 50, | ||
]); | ||
$menuLink->save(); | ||
} |
8 changes: 8 additions & 0 deletions
8
modules/custom/openy_gtranslate/openy_gtranslate.libraries.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
translate: | ||
version: 8.0.1 | ||
js: | ||
js/openy_gtranslate.js: {} | ||
dependencies: | ||
- core/jquery | ||
- core/drupal | ||
- core/drupalSettings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Defines the OpenY Google Translate module functions. | ||
*/ | ||
|
||
/** | ||
* Implements hook_preprocess_menu(). | ||
* | ||
* Add class to menu navigation items. | ||
*/ | ||
function openy_gtranslate_preprocess_menu(&$vars) { | ||
if (isset($vars['menu_name']) && in_array($vars['menu_name'], ['main', 'account'])) { | ||
foreach ($vars['items'] as &$item) { | ||
/* @var \Drupal\Core\Url $url */ | ||
$url = $item['url']; | ||
$attr = $url->getOption('attributes'); | ||
if (!empty($attr['class'])) { | ||
/* @var \Drupal\Core\Template\Attribute $item['attributes'] */ | ||
$item['attributes']->addClass($attr['class']); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_theme(). | ||
*/ | ||
function openy_gtranslate_theme($existing, $type, $theme, $path) { | ||
return [ | ||
'openy_gtranslate' => [ | ||
'variables' => [], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Implements hook_preprocess_block(). | ||
*/ | ||
function openy_gtranslate_preprocess_block(&$variables) { | ||
$blockType = $variables['elements']['#configuration']['provider']; | ||
|
||
if ($blockType == 'openy_gtranslate') { | ||
$variables['attributes']['class'][] = 'openy-gtranslate'; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
modules/custom/openy_gtranslate/src/Plugin/Block/OpenYGTranslateBlock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Drupal\openy_gtranslate\Plugin\Block; | ||
|
||
use Drupal\Core\Block\BlockBase; | ||
|
||
/** | ||
* Provides a 'OpenY Google Translate' block. | ||
* | ||
* @Block( | ||
* id = "openy_gtranslate_block", | ||
* admin_label = @Translation("OpenY Google Translate"), | ||
* category = @Translation("OpenY"), | ||
* ) | ||
*/ | ||
class OpenYGTranslateBlock extends BlockBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build() { | ||
$block = [ | ||
'#theme' => 'openy_gtranslate', | ||
'#attached' => [ | ||
'library' => ['openy_gtranslate/translate'], | ||
], | ||
]; | ||
|
||
return $block; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
modules/custom/openy_gtranslate/templates/openy-gtranslate.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{# | ||
/** | ||
* @file | ||
* Template for the OpenY Google Translate block | ||
*/ | ||
#} | ||
|
||
<div class="openy-google-translate" id="google_translate_element"></div> | ||
<script type="text/javascript"> | ||
function googleTranslateElementInit() { | ||
new google.translate.TranslateElement({pageLanguage: drupalSettings.path.currentLanguage, layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element'); | ||
} | ||
</script> | ||
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.