diff --git a/config/config-default/language.entity.zh-hant.yml b/config/config-default/language.entity.zh-hant.yml new file mode 100644 index 00000000..80c5afea --- /dev/null +++ b/config/config-default/language.entity.zh-hant.yml @@ -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 diff --git a/config/config-default/language.negotiation.yml b/config/config-default/language.negotiation.yml index f360c5e4..2bde669c 100644 --- a/config/config-default/language.negotiation.yml +++ b/config/config-default/language.negotiation.yml @@ -15,6 +15,7 @@ url: fa: fa zh-hans: zh-hans vi: vi + zh-hant: zh-hant domains: en: '' es: '' @@ -26,4 +27,5 @@ url: fa: '' zh-hans: '' vi: '' + zh-hant: '' selected_langcode: site_default diff --git a/config/config-default/search_api_solr.solr_field_type.text_zh-hans_7_0_0.yml b/config/config-default/search_api_solr.solr_field_type.text_zh-hans_7_0_0.yml new file mode 100644 index 00000000..35fd7f06 --- /dev/null +++ b/config/config-default/search_api_solr.solr_field_type.text_zh-hans_7_0_0.yml @@ -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: { } diff --git a/config/config-default/search_api_solr.solr_field_type.text_zh-hant_7_0_0.yml b/config/config-default/search_api_solr.solr_field_type.text_zh-hant_7_0_0.yml new file mode 100644 index 00000000..d6c73edf --- /dev/null +++ b/config/config-default/search_api_solr.solr_field_type.text_zh-hant_7_0_0.yml @@ -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: { } diff --git a/web/themes/custom/atrium/includes/page.inc b/web/themes/custom/atrium/includes/page.inc index e83fad89..a8722beb 100644 --- a/web/themes/custom/atrium/includes/page.inc +++ b/web/themes/custom/atrium/includes/page.inc @@ -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(). @@ -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) { @@ -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; } @@ -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(); @@ -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"); + } +} diff --git a/web/themes/custom/atrium/templates/page/page-header.twig b/web/themes/custom/atrium/templates/page/page-header.twig index 7e269a85..69f92ea6 100644 --- a/web/themes/custom/atrium/templates/page/page-header.twig +++ b/web/themes/custom/atrium/templates/page/page-header.twig @@ -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"