By admin , 12 October, 2023 Get language code from JavaScript let langCode = drupalSettings.path.currentLanguage; console.log(langCode); Tags javascript translate
By admin , 7 July, 2023 Get entity translation $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); if ($term->hasTranslation($language)) { $term_translated = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language); $term_title = $term_translated->getName(); } Tags translate
By admin , 1 April, 2023 Make custom entity translatable Add to file src/Entity/MyEntity.php/** * Defines the my entity class. * * @ContentEntityType( ... * data_table = "my_entity_field_data", * translatable = TRUE, ... * entity_keys = { ... * "langcode" = "langcode" * }, ... * ) */Add ->setTranslatable(TRUE) to baseFieldDefinitions. For example Tags translate custom entity
By admin , 31 March, 2023 Get the current language programmatically Get Language ID$language = \Drupal::languageManager()->getCurrentLanguage()->getId();Get Language name$language = \Drupal::languageManager()->getCurrentLanguage()->getName(); Tags translate
By admin , 31 March, 2023 Translate string in TWIG Use {% trans %} and {% endtrans %} Tags twig translate
By admin , 31 March, 2023 Translate string in JavaScript Use Drupal.tvar optionsList = '<option value="" selected>' + Drupal.t('Navigate...') + '</option>'; Tags javascript translate
By admin , 24 February, 2023 Add translate context to string $this->t('April', [], ['context' => 'Long month name']), Tags translate