Skip to content

Commit

Permalink
Merge pull request #915 from chapter-three/deployment/20230621b
Browse files Browse the repository at this point in the history
Deployment/20230621b
  • Loading branch information
ivanbueno-jcc authored Jun 22, 2023
2 parents 4cef234 + b4666de commit 5a74b7a
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 24 deletions.
9 changes: 9 additions & 0 deletions config/config-default/language.entity.zh-hant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
uuid: eb36db4e-0d0d-40d0-bb9c-083b599072f7
langcode: en
status: true
dependencies: { }
id: zh-hant
label: 'Chinese, Traditional'
direction: ltr
weight: 0
locked: false
2 changes: 2 additions & 0 deletions config/config-default/language.negotiation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ url:
fa: fa
zh-hans: zh-hans
vi: vi
zh-hant: zh-hant
domains:
en: ''
es: ''
Expand All @@ -26,4 +27,5 @@ url:
fa: ''
zh-hans: ''
vi: ''
zh-hant: ''
selected_langcode: site_default
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
uuid: 47ed4b72-c232-4a32-93c2-83becc17e29c
langcode: en
status: true
dependencies: { }
_core:
default_config_hash: xsPPP97vkAKhvY3wcrNJa8L0y1G2-GJ4Falq0T6nrrw
id: text_zh-hans_7_0_0
label: 'Simplified Chinese Text Field'
minimum_solr_version: 7.0.0
custom_code: null
field_type_language_code: zh-hans
domains: { }
field_type:
name: text_zh_hans
class: solr.TextField
positionIncrementGap: 100
analyzers:
-
type: index
tokenizer:
class: solr.HMMChineseTokenizerFactory
filters:
-
class: solr.CJKWidthFilterFactory
-
class: solr.StopFilterFactory
words: org/apache/lucene/analysis/cn/smart/stopwords.txt
-
class: solr.PorterStemFilterFactory
-
class: solr.LowerCaseFilterFactory
-
type: query
tokenizer:
class: solr.HMMChineseTokenizerFactory
filters:
-
class: solr.CJKWidthFilterFactory
-
class: solr.StopFilterFactory
words: org/apache/lucene/analysis/cn/smart/stopwords.txt
-
class: solr.PorterStemFilterFactory
-
class: solr.LowerCaseFilterFactory
unstemmed_field_type:
name: text_unstemmed_zh_hans
class: solr.TextField
positionIncrementGap: 100
analyzers:
-
type: index
tokenizer:
class: solr.HMMChineseTokenizerFactory
filters:
-
class: solr.CJKWidthFilterFactory
-
class: solr.StopFilterFactory
words: org/apache/lucene/analysis/cn/smart/stopwords.txt
-
class: solr.LowerCaseFilterFactory
-
type: query
tokenizer:
class: solr.HMMChineseTokenizerFactory
filters:
-
class: solr.CJKWidthFilterFactory
-
class: solr.StopFilterFactory
words: org/apache/lucene/analysis/cn/smart/stopwords.txt
-
class: solr.LowerCaseFilterFactory
spellcheck_field_type:
name: text_spell_zh_hans
class: solr.TextField
positionIncrementGap: 100
analyzer:
tokenizer:
class: solr.HMMChineseTokenizerFactory
filters:
-
class: solr.CJKWidthFilterFactory
-
class: solr.LowerCaseFilterFactory
collated_field_type:
name: collated_zh-hans
class: solr.ICUCollationField
locale: zh
strength: primary
caseLevel: false
solr_configs:
searchComponents:
-
name: spellcheck
class: solr.SpellCheckComponent
lst:
-
name: spellchecker
str:
-
name: name
VALUE: zh_hans
-
name: field
VALUE: spellcheck_zh_hans
-
name: classname
VALUE: solr.DirectSolrSpellChecker
-
name: distanceMeasure
VALUE: internal
-
name: accuracy
VALUE: '0.5'
-
name: maxEdits
VALUE: '1'
-
name: minPrefix
VALUE: '1'
-
name: maxInspections
VALUE: '5'
-
name: minQueryLength
VALUE: '1'
-
name: maxQueryFrequency
VALUE: '0.01'
-
name: onlyMorePopular
VALUE: 'true'
text_files: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
uuid: 43bf5656-6e75-4fa0-8f14-c06b10d36e4c
langcode: en
status: true
dependencies: { }
_core:
default_config_hash: 6F7KHstVnd5Suu1qCf84KQ11m-U6F467xghzRtEu360
id: text_zh-hant_7_0_0
label: 'Traditional Chinese Text Field'
minimum_solr_version: 7.0.0
custom_code: null
field_type_language_code: zh-hant
domains: { }
field_type:
name: text_zh_hant
class: solr.TextField
positionIncrementGap: 100
analyzers:
-
type: index
tokenizer:
class: solr.ICUTokenizerFactory
filters:
-
class: solr.CJKBigramFilterFactory
han: true
hiragana: false
katakana: false
hangul: false
outputUnigrams: false
-
class: solr.CJKWidthFilterFactory
-
class: solr.LowerCaseFilterFactory
-
type: query
tokenizer:
class: solr.ICUTokenizerFactory
filters:
-
class: solr.CJKBigramFilterFactory
han: true
hiragana: false
katakana: false
hangul: false
outputUnigrams: false
-
class: solr.CJKWidthFilterFactory
-
class: solr.LowerCaseFilterFactory
unstemmed_field_type: null
spellcheck_field_type:
name: text_spell_zh_hant
class: solr.TextField
positionIncrementGap: 100
analyzer:
tokenizer:
class: solr.ICUTokenizerFactory
filters:
-
class: solr.CJKBigramFilterFactory
han: true
hiragana: false
katakana: false
hangul: false
outputUnigrams: false
-
class: solr.CJKWidthFilterFactory
-
class: solr.LowerCaseFilterFactory
collated_field_type:
name: collated_zh-hant
class: solr.ICUCollationField
locale: zh-hant
strength: primary
caseLevel: false
solr_configs:
searchComponents:
-
name: spellcheck
class: solr.SpellCheckComponent
lst:
-
name: spellchecker
str:
-
name: name
VALUE: zh_hant
-
name: field
VALUE: spellcheck_zh_hant
-
name: classname
VALUE: solr.DirectSolrSpellChecker
-
name: distanceMeasure
VALUE: internal
-
name: accuracy
VALUE: '0.5'
-
name: maxEdits
VALUE: '1'
-
name: minPrefix
VALUE: '1'
-
name: maxInspections
VALUE: '5'
-
name: minQueryLength
VALUE: '1'
-
name: maxQueryFrequency
VALUE: '0.01'
-
name: onlyMorePopular
VALUE: 'true'
text_files: { }
67 changes: 44 additions & 23 deletions web/themes/custom/atrium/includes/page.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Component\Utility\Html;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\menu_link_content\Plugin\Menu\MenuLinkContent;
use Drupal\webform\Entity\Webform;

/**
* Implements hook_preprocess_HOOK().
Expand Down Expand Up @@ -171,12 +172,9 @@ function _atrium_get_menutree($menu_name) {
*/
function _atrium_translation_menu() {

$host = \Drupal::request()->getSchemeAndHttpHost();
$language_manager = \Drupal::languageManager();
$languages = $language_manager->getLanguages();
$default_language = $language_manager->getDefaultLanguage();
$current_path = \Drupal::request()->getRequestUri();
$prefixed_current_path = \Drupal::request()->getRequestUri();

// Strip language from current path.
foreach ($languages as $langcode => $language) {
Expand All @@ -185,28 +183,23 @@ function _atrium_translation_menu() {
? str_replace("/$langcode", '', $current_path)
: $current_path;
}
// Create links for dropbutton component if translated content exists for page.
$links = [];
// Create links for dropbutton component if translated content or webform exists for page.
$links = array();
$node = \Drupal::routeMatch()->getParameter('node');
$webform = \Drupal::routeMatch()->getParameter('webform');
foreach ($languages as $langcode => $language) {
$node = \Drupal::routeMatch()->getParameter('node');

$translate_link = '';
if ($webform instanceof Drupal\webform\Entity\Webform && $webform->hasTranslation($langcode)) {
$translate_link = _atrium_translate_menu_dropbutton($webform,'webform', $langcode, $language);
}
if ($node instanceof \Drupal\node\NodeInterface && $node->hasTranslation($langcode)) {
// You can get nid and anything else you need from the node object.
$translated_path = \Drupal::service('path_alias.manager')->getAliasByPath('/node/'. $node->id(), $langcode);
$prefixed_translated_path = '/' . $langcode . $translated_path;

// Default language paths have no prefix.
$langcode = $langcode == $default_language->getId() ? '' : "/$langcode";

if($node != null
&& $prefixed_translated_path != $prefixed_current_path
&& $prefixed_translated_path != '/en' . $prefixed_current_path
&& $translated_path != \Drupal::service('path_alias.manager')->getAliasByPath('/node/'. $node->id())){
$links[] = [
'title' => $language->getName(),
'href' => "$host$langcode$translated_path",
];
}
$translate_link = _atrium_translate_menu_dropbutton($node,'node', $langcode, $language);
}
if(!empty($translate_link)){
$links[] = $translate_link;
}

}
return $links;
}
Expand All @@ -215,7 +208,7 @@ function _atrium_translation_menu() {
* Format Global language links for drobputton component.
*
* @return array
* Array of global link items for dropbutton component.
* Callback function written for dropbutton component.
*/
function _atrium_global_translation_menu() {
$host = \Drupal::request()->getSchemeAndHttpHost();
Expand All @@ -230,3 +223,31 @@ function _atrium_global_translation_menu() {
}
return $global_links;
}

/**
* Format translation links for drobputton component.
*
* @return array
* Array of translation link items for dropbutton component.
*/
function _atrium_translate_menu_dropbutton($entity, $entity_path_name, $langcode, $language) {

$host = \Drupal::request()->getSchemeAndHttpHost();
$language_manager = \Drupal::languageManager();
$default_language = $language_manager->getDefaultLanguage();
$prefixed_current_path = \Drupal::request()->getRequestUri();

// You can get webform id and anything else you need from the webform object.
$translated_path = \Drupal::service('path_alias.manager')->getAliasByPath('/' . $entity_path_name . '/' . $entity->id(), $langcode);
$prefixed_translated_path = '/' . $langcode . $translated_path;
// Default language paths have no prefix.
$langcode = $langcode == $default_language->getId() ? '' : "/$langcode";

if ( ($entity != null
&& $prefixed_translated_path != $prefixed_current_path
&& $prefixed_translated_path != '/en' . $prefixed_current_path)
&& (($translated_path != \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $entity->id()) && $entity_path_name == 'node')
|| $entity_path_name=='webform') ) {
return array('title' => $language->getName(), 'href' => "$host$langcode$translated_path");
}
}
2 changes: 1 addition & 1 deletion web/themes/custom/atrium/templates/page/page-header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
accordion_button: {
id: 'extended-nav-section-two',
label: 'Translate',
label: 'Languages',
links: translation_links,
global_links: global_links,
global_links_label: "More languages resources"
Expand Down

0 comments on commit 5a74b7a

Please sign in to comment.