Skip to content

Commit

Permalink
Automatically translate to the right language.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacha committed Oct 2, 2024
1 parent 1a27cad commit 728f4d4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/wri_common/wri_common.module
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ function wri_common_get_node_topic_children(Node $node) {
function _wri_common_format_list(array $terms) {
$list = '';
if ($terms) {
$lang_code = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
foreach ($terms as $term) {
if ($term->hasTranslation($lang_code)) {
$term = $term->getTranslation($lang_code);
}
$published = $term->isPublished();
if ($published) {
$term_url = $term->toUrl();
Expand Down Expand Up @@ -446,6 +450,10 @@ function _wri_common_format_list(array $terms) {
* A string representing the entity with or without a link.
*/
function wri_common_link_or_text(EntityInterface $entity, ?NodeInterface $node = NULL) {
$lang_code = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
if ($entity->hasTranslation($lang_code)) {
$entity = $entity->getTranslation($lang_code);
}
$link = '';
if (isset($entity)) {
if ($entity->isPublished()) {
Expand Down

0 comments on commit 728f4d4

Please sign in to comment.