Follow up for #1977784: Content language settings configuration page needs to determine what entities and bundles to include
Problem/Motivation
confusing terms: translatable, multilingual, language-aware, untranslatable, non-translatable, not translatable, enable translation, translation enabled/disabled/not enabled
It's confusing in code, code comments, and UI
UI
In the UI, to enable translation, the checkboxes usually are for making it "translatable".
- admin/structure/types/manage/article/fields/node.article.field_image where parts of the image field can be checked off to be "Translatable elements"
- admin/config/regional/content-language content language settings page where the header to the column is "translatable"
- admin/structure/types/manage/article where Translation is "Enable translation"
- admin/structure/types/manage/article/fields/node.article.body/field-settings is "Users may translate this field."
code and the code comments
the translatable setting is really (imo) whether translation is enabled
and that is set only when something is translatable. things that are not translatable do not have 'translatable' set either way.
core/lib/Drupal/Core/Entity/Annotation/EntityType.php
/**
* Boolean indicating whether entities of this type have multilingual support.
*
* At an entity level, this indicates language support and at a bundle level
* this indicates translation support.
*
* @var bool (optional)
*/
public $translatable = FALSE;
core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php
/**
* Defines the node entity class.
*
* @EntityType(
* id = "node",
* label = @Translation("Content"),
* bundle_label = @Translation("Content type"),
* module = "node",
* controllers = {
* "storage" = "Drupal\node\NodeStorageController",
* "render" = "Drupal\node\NodeRenderController",
* "access" = "Drupal\node\NodeAccessController",
* "form" = {
* "default" = "Drupal\node\NodeFormController"
* },
* "translation" = "Drupal\node\NodeTranslationController"
* },
* base_table = "node",
* revision_table = "node_revision",
* uri_callback = "node_uri",
* fieldable = TRUE,
* translatable = TRUE,
core/modules/language/language.module
/**
* Returns a list of supported entity types.
*
* @return array
* An array of entity type names.
*/
function language_entity_supported() {
$supported = array();
foreach (entity_get_info() as $entity_type => $info) {
if (!empty($info['translatable'])) {
$supported[$entity_type] = $entity_type;
}
}
return $supported;
}
core/modules/translation_entity/translation_entity.module
function translation_entity_preprocess_language_content_settings_table(&$variables) {
module_load_include('inc', 'translation_entity', 'translation_entity.admin');
_translation_entity_preprocess_language_content_settings_table($variables);
}
/**
* Stores entity translation settings.
*
* @param array $settings
* An associative array of settings keyed by entity type and bundle. At bundle
* level the following keys are available:
* - translatable: The bundle translatability status, which is a bool.
* - settings: An array of language configuration settings as defined by
* language_save_default_configuration().
* - fields: An associative array with field names as keys and a boolean as
* value, indicating field translatability.
* - columns: An associative array of translation synchronization settings
* keyed by field names.
*/
function translation_entity_save_settings($settings) {
foreach ($settings as $entity_type => $entity_settings) {
foreach ($entity_settings as $bundle => $bundle_settings) {
// The 'translatable' value is set only if it is possible to enable.
if (isset($bundle_settings['translatable'])) {
// Store whether a bundle has translation enabled or not.
translation_entity_set_config($entity_type, $bundle, 'enabled', $bundle_settings['translatable']);
core/modules/translation_entity/translation_entity.admin.inc
for example, function _translation_entity_form_language_content_settings_form_alter
Proposed resolution
- In #1977784-12: Content language settings configuration page needs to determine what entities and bundles to include @plach suggested renaming the translatable annotation to multilingual
- Maybe some cleaning up of comments.
- Maybe a way to store if something is translatable (multilingual/capable of having translation enabled or disabled) in the config/arrays
- ?
Remaining tasks
Discuss.
Document.
Discuss if there is a need to make the UI more consistant, if so, open an issue.
User interface changes
TBD
API changes
TBD
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedin the code to know if something can have translation enabled, so that it can be translated by users in the ui,
check the entity info for the translatable annotation
if it has fields
[if it has fields that can have translation enabled] (I think we said all fields can be translated so we dont have to check if the field type is translatable)
In the UI, something is translatable (translatable checkbox checked) or not translatable (translation checkbox not checked).
There is also sometimes no choice to be translatable... this no choice is maybe.. not multilingual/language-aware? And there is where in the entity info annotation, translatable = TRUE is used to indicate that it should be able to chose translatable or not, *if* the other conditions for translatable are met like: fieldable and has fields.
language_entity_supported() used to check if it was fieldable. fieldable is not needed for language support but maybe we need a function for
translation_entity_supported() to check the entity info, if it has fields?
when properties are fields, there may not be any entity that does not have something that can be translated.. so we might not have to check for fields anymore.
Comment #2
YesCT CreditAttribution: YesCT commentedComment #2.0
YesCT CreditAttribution: YesCT commentedadded related issues
Comment #2.1
YesCT CreditAttribution: YesCT commentedadded mutlilingual and language aware.
Comment #2.2
YesCT CreditAttribution: YesCT commentedadded some code examples. (might be better as a comment so as not to clutter the issue summary..)
Comment #2.3
YesCT CreditAttribution: YesCT commented"this" referred to the other issue
Comment #3
Gábor HojtsyComment #3.0
Gábor Hojtsyadded an example of the translatable setting used on bundles to mean translation support.
Comment #16
joachim CreditAttribution: joachim at Factorial GmbH commentedThis is still a relevant issue. Adding the term language-alterable which I encountered recently.