5

{{ language }} works but only in page context. The example of this question(page--front.html.twig) happens to be a working one. I tried in 8.7.6 with Xdebug. When called from somewhere other than page.html.twig it will returns a null instead of {Drupal\Core\Language\Language} I think that's why some people report it working but others not. You might use ...


4

Comparing TermSelection::getReferenceableEntities and ViewsSelection::getReferenceableEntities it seems like the Views entity reference selection plugin doesn't translate the entity before returning the entity labels. It should work with a core patch adding one line: /core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php: public ...


4

To translate action labels install the core module Actions and go to /admin/config/regional/config-translation/action. Actions are config entities, which you can translate in an exported config as well, if you don't want to install the UI option.


4

Could be caused by a module which doesn't provide a base path for a config entity, see for example: https://www.drupal.org/project/dynamic_layouts/issues/3002255 https://www.drupal.org/project/password_policy/issues/2703717 https://www.drupal.org/project/paragraphs_entity_embed/issues/3014901 https://www.drupal.org/project/search_api/issues/2919676 https://...


4

Do not use the raw field value, use the render array of the field instead: {{ content.field_stories }} This will automatically use the correct language. NOT RECOMMENDED: If you have to go the custom, raw value route you can do something like {% for story in node.field_stories %} {% if story.entity.hasTranslation('iso2_langcode') %} {{ story.entity....


3

How is this possible and how can I programmatically set the translations for my field(s)? You can load language overrides with ConfigurableLanguageManager::getLanguageConfigOverride, set values and save: \Drupal::languageManager()->getLanguageConfigOverride('fr', 'field.storage.node.field_example') ->set($key, $value) ->save();


3

Unset the field values in a hook_ENTITY_TYPE_translation_create: use Drupal\node\NodeInterface; /** * Implements hook_ENTITY_TYPE_translation_create(). */ function mymodule_node_translation_create(Nodeinterface $translation) { if ($translation->getType() == 'product') { unset($translation->body); } }


3

You can try using hook_entity_translation_insert and use a common logic with hook_entity_insert


3

If you intend to remove ALL strings imported through interface translation, you could execute something like this: // Replace the empty string with your target language code. $langcode = ''; \Drupal::database() ->delete('locales_target'); ->condition('language', $langcode) ->condition('customized', 0) ->execute(); You may also want to ...


3

In page.html.twig and Drupal 8.7.6, I had to use: {% if language.id == 'en' %} or {{ language.id == 'en' ? 'active' : 'not-active' }} Other suggestions did not work.


2

Here is an example I used where the language is explict provided, as well as an context. Like this I was able to translate the sting 'von' twice, as in english it meant 'of' or 'from'. {{ 'von'|t([],{'langcode': currentLanguageCode,'context':'Seitenzahl PDF' }) }}


2

This tool used to be called "Translate interface" in Drupal 7, and it seems they should have stuck to the name. No, this tool doesn't actually translate the interface, it only stores the translations you enter there yourself, it allows you to search through existing strings and enter new translations. As suggested in the comment you may find outside ...


2

The Views list is a config entity list and these are listed override free: ConfigEntityListBuilder::load public function load() { $entity_ids = $this->getEntityIds(); $entities = $this->storage->loadMultipleOverrideFree($entity_ids); // Sort the entities using the entity class's sort() method. // See \Drupal\Core\Config\Entity\...


2

Drupal multilingual features are very versatile and can cover most if not all cases. It is still a fairly complex feature and it is necessary to understand some concepts before you know how to configure everything to satisfy a particular need. The most important concept to understand in your case is the two-part nature of the multilingual system. One part ...


2

A simple solution in such cases would be to remove the language switcher and provide for translated content only modal links: <a class="use-ajax" data-dialog-type="modal" data-dialog-options="{&quot;width&quot;:800}" href="/fr/node/1">French version</a> You could add the links to the node, in a template or preprocess hook. Or create a ...


2

By default only the image alt and title are translatable and the file itself isn't. By the default the file is always the same in all languages. You can simply make the file to be translatable as well under https://example.com/admin/config/regional/content-language. Note: After you've done this, all your existing translations will need to have the file re-...


2

To have the "Translate" tab listed on your module's configuration page you additionally need to provide a module_name.config_translation.yml in your module's root. module_name.settings: title: 'Module Name' base_route_name: module_name.admin_settings names: - module_name.settings Look for existing module_name.config_translation.yml file in core ...


2

This is an extra field (Drupal term for a pseudo field not stored in the database you can move around in UI), which is added when Content Translation is enabled: content_translation_entity_extra_field_info() See this issue: content_translation_entity_extra_field_info is obsolete Problem/Motivation content_translation_entity_extra_field_info is ...


1

I found a solution: call field_attach_view with the required language. /** * Implements hook_preprocess_node(). */ function MYMODULE_preprocess_node(&$vars) { if ($GLOBALS['language']->language == 'ru') { $original_langcode = 'en'; $content_original = field_attach_view('node', $vars['node'], $vars['view_mode'], $original_langcode); //...


1

I was able to reproduce your issue in a fresh Drupal 8.7.5 installation. I reported the issue in Drupal core issue tracker. Also, here are a screenshot in which French Views names are displayed in an English interface:


1

Just to add to prkos's excellent accepted answer, I found that once I configured my website according to his instructions, if I really wanted to let end users use /fr/ language path prefixes, thereby making pages accessible without full-site switching at paths like /fr/node/1, I could do so via the following .htaccess / mod_rewrite rule: RewriteRule "^fr/(.*...


1

Use /admin/config/regional/language/detection to set how language is detected. Add the language switcher module someplace to let a user change language. I find that when I switch a language, menu items adjust to the current language. So create the menu item to /somelink and change my language to Japanese, change the link to /ja/somelink when the menu ...


1

For what you are trying to achieve I found out you can use the Menu Manipulator module. This module initially aimed to fix [Issue] Untranslated menu items are displayed in menus. Notes This module initially aims to fix this core issue with unstranslated menu items. Having this module installed only menu items that are available in the current ...


1

The domain associated with each language is stored as configuration. Using the following code, $prefix will contain the prefix, and $domain the domain used. $config = \Drupal::configFactory()->get('language.negotiation'); $languages = \Drupal::languageManager()->getLanguages(); $prefixes = $config->get('url.prefixes'); $domains = $config-&...


1

Drupa8 - as a Symfony application - abstracts paths with routes. So paths may change, the route stays. So the cited "The internal: scheme should be avoided except when processing actual user input that may or may not correspond to a Drupal route." means: If you can, use a route. If you can not use routes, the right prefix for routed paths is internal:. In ...


1

Drupal has very advanced Multi-lingual capabilities, so it's safe to assume that you can configure your site according to your needs. You just have to learn a bit about Drupal multilingual fundamentals and see how your needs fit in there. It seems your question is about how languages are selected and displayed, and not about Interface translation. You ...


1

In Drupal 8 LANGUAGE_NONE (neutral) has changed to LANGUAGE_NOT_SPECIFIED, LANGUAGE_NOT_APPLICABLE and LANGUAGE_MULTIPLE. I usually use LANGUAGE_NOT_SPECIFIED where I used to use LANGUAGE_NONE in Drupal 7. Berdir mentions that all those new options makes no difference to how content is displayed, but they let you treat differently to content on your site ...


1

Suggestion 1 if you want to get rid of all translations of a language, just delete the langauge in /admin/config/regional/language Suggestion 2 if there are some specific string you want to be not translated, Go to locales_source to identify those strings lids, then execute the following code (devel/php or custom hook_update_N or drush ev...) $lids ...


Only top voted, non community-wiki answers of a minimum length are eligible