backdrop / backdrop-issues

Issue tracker for Backdrop core.
145 stars 40 forks source link

[UX] Missing translation function calls #4022

Open VasasA opened 5 years ago

VasasA commented 5 years ago

Description of the bug node.module and standard.install are missing translation function calls needed for localization. Unable to translate some strings of the "Add content" page (Create Post) and the welcome page.

kép

kép

I created two PR: https://github.com/backdrop/backdrop/pull/2858 https://github.com/backdrop/backdrop/pull/2866

(Don't watch the invalid closed PRs: 2859, 2860, 2864)

Testing:

  1. Download the Backdrop 1.16.2
  2. Replace the core/profiles/standard/standard.install file with this (2858): https://raw.githubusercontent.com/VasasA/backdrop/patch-1/core/profiles/standard/standard.install
  3. Replace the core/modules/node/node.module file with this (2866): https://raw.githubusercontent.com/VasasA/backdrop/patch-10/core/modules/node/node.module
  4. From https://localize.backdropcms.org/translate/languages download a translation file. Check and edit the file: It must contain the following strings: About, Title, Body, Tags, Image, Filtered HTML, Full HTML
  5. Place the translation file into the following directory: ./files/translations
  6. Install Backdrop CMS with the selected language.
  7. Check the translated strings at the welcome page and the "Content > Add content > Post" page according to the screenshots above.

FTR, these were the respective original issues in d.org:

https://www.drupal.org/project/drupal/issues/1016006 https://www.drupal.org/project/drupal/issues/1130732

They have been closed as duplicates of either of the following:

D8: https://www.drupal.org/project/drupal/issues/2571337 D9: https://www.drupal.org/project/drupal/issues/1157426 (which the way I understand it, is basically the respective #704)

VasasA commented 5 years ago

Sorry, the second (2859) PR is bad. :cry:

klonos commented 5 years ago

...also FTR, in case that PR is closed in the future, we should not be translating variables directly by wrapping them in t():

Screen Shot 2019-09-10 at 4 29 24 am

...there's more to it: https://api.backdropcms.org/api/backdrop/core%21includes%21bootstrap.inc/function/t/1

klonos commented 4 years ago

Hello @VasasA 👋 ...most (all?) of the things you are translating are things that are saved in config. In such cases, the proper way to translate them is via the _config_translatables section in the respective .json files. For an example, see https://github.com/backdrop/backdrop/blob/1.x/core/modules/system/config/system.core.json

The problem is that while things like site name/slogan and anonymous name are "unique" things that are saved in a single config file, translatable strings that belong to multiple things, like menus, content types, vocabularies etc. need to be saved in each individual config file, and there can be multiple of them.

To better explain things with examples, we'd need to have this chunk here:

    "_config_translatables": [
        "label"
    ],

...added to every single field.instance.*.json file:

Then we'd also need this:

    "_config_translatables": [
        "name"
    ],

...added to every single filter.format.*.json file:

For layouts, it'd need to be:

    "_config_translatables": [
        "title"
    ],

...and so on for things like menus, vocabularies, user roles etc. I think that this was meant to be either done as part of #704, or as a follow-up issue (but I can't find any).

Anyway, what I mean to say is that unless I'm mistaken, the way you are approaching this in your PRs may work, but it's not the proper way. For instance, the "Body" label is the default added when you are creating a content type, but it may need to be different for each content type (although most sites won't change it TBH). There may also be other things that won't work as expected that I can't think of right now.

klonos commented 4 years ago

@herbdool and @quicksketch have more context re this I believe. Please chime in to clarify. Thanks.

herbdool commented 4 years ago

There's this issue https://github.com/backdrop/backdrop-issues/issues/3515 which covers some of this but not specifically fields. Same idea though. Harder to implement so they haven't been done yet.

herbdool commented 4 years ago

Just looking into the process. So as @klonos noted, the first step is to include, for example,

"_config_translatables": [
        "label"
    ],

in the config files. We'll need to add them and also trigger locale to scan them so they can show up as translatable. That part I've tested and it works.

Then we'll either need to use https://api.backdropcms.org/api/backdrop/core%21includes%21config.inc/function/config_get_translated/1 or something similar to actually fetch the translation for display. I haven't tried to do this part yet.