Just committed http://cgit.drupalcode.org/google_analytics/commit/?id=480df1d, but I cannot get the variables translated. The link shows up in admin/config/regional/config-translation, but if I click it I get an access denied at admin/config/system/google-analytics/translate.

I guess I missed anything - but what?

Comments

hass’s picture

Component: configuration system » config_translation.module
Category: Support request » Bug report
gábor hojtsy’s picture

Is 'account' a config name used by the google analytics module, such as \Drupal::config('account'). Like this? No module name prefix in there?

hass’s picture

In PHP code I'm using:

$config = \Drupal::config('google_analytics.settings');
$id = $config->get('account');

Do I need to prefix the variable like google_analytics.settings.account? I thought that context comes from base_route_name or google_analytics.settings: (first line). The structure of the file is really unclear to me. No idea why first line and base_route_name are the same in all files I've found. And there are no docs about this yet.

google_analytics.settings:
  title: 'Google Analytics'
  base_route_name: google_analytics.settings
  names:
    - account

For me it looks like the translation tab does not exists and is causing the access denied.

gábor hojtsy’s picture

You DO NOT have a config object named 'account'. The config name used by your module is 'google_analytics.settings', account is one of the keys, not a config name. You named your route the same as your config name which mislead you. The 'names' list takes config names. Your config name is 'google_analytics.settings'.

hass’s picture

You mean it should be like this??? I should change my route name than...

google_analytics.settings_form:
  title: 'Google Analytics'
  base_route_name: google_analytics.settings_form
  names:
    - google_analytics.settings

I thought the Names are all keys that should be translatable as not everything in a string should be a translatable string. Additional to this - how can I prevent l.d.o from making my "translatable" configuration strings translatable on d.o? Well, some of the settings should be configurable per language, but not "translatable" the classic way like t() strings.

Is there any documentation about the .config_translation.yml files? It's very confusing to me what is in the API file. Looking for something like:

[this is the route name used in "module.menu_links.yml"]:
  title: 'The title used for the above route name in "module.menu_links.yml" or is this just the button name shown on config translation page?'
  base_route_name: [this is the route name used in module.menu_links.yml, but why the heck the same like above? e.g. mymodule.admin_form]
  names:
    - [the config object name like "mymodule.settings"]

Please correct if something is wrong... and let's follow up with a patch for the API file for clarification.

gábor hojtsy’s picture

1. Yes that config translation YAML file looks good. The names list is all configuration names, AKA config object names AKA config file names (without extension).

2. Drupal core only supports translation not per language values, at least localize.drupal.org will extract all the items that are marked for translation. The core config translation module only supports widgets for text types (although this is extensible to some degree in your own module). This is already worlds apart from what Drupal 7 was capable of.

3. The file structure is very similar to the local tasks, contextual links, etc. YAML structures. The base route is the route the mapping is attached to. The top level key is the name of the mapping, which could also be boo.i.am.tired but we use the same key as the base route name as a convention. The same is true across the other plugin YAML files, like local tasks, actions, contextual links, menu links, etc. I am not sure where this could be documented in the codebase, are local tasks, etc. documented like this in the codebase? I think the best place to document would be the drupal.org handbook. Eg. local tasks are at https://drupal.org/node/2122253 explaining the difference between the plugin ID and the base route name. I think a sub-page at https://drupal.org/developing/api/8/configuration for configuration translation would be in order. Wanna start on one?

hass’s picture

Huh, yeah that is all 1000 times better than D7, but I do not think it is a good idea to push all my settings to l.d.o and I really think this might end with horrible troubles as people may start translating settings that are just site specific and not language specific. I think we need something to tell l.d.o to not extract the strings. Otherwise... lots and lots of new troubles...

Something like:

    account:
      type: string
      label: 'Web Property ID'
      translatable: true
      potx: false
gábor hojtsy’s picture

Well, only your settings that are translatable are parsed on l.d.o, so no, your settings will not end up on l.d.o if you don't make them use the 'label' and 'text' types (or for some reason make translatable strings like you do in this example which is a lot less effective). No need to try to use a feature that does not exist in core.

hass’s picture

Changed all route names, but still get access denied. Pressed several times clear cache and then also tried uninstalling and re-installing GA. No success.

gábor hojtsy’s picture

Looking at http://cgit.drupalcode.org/google_analytics/tree/config/schema/google_an... none of your elements use a translatable type ('label' for one line translatable strings and 'text' for multiline), so there is no point in doing a translate tab, right? Translate routes that point to configuration that does not have translatable things end up access denied. Use the 'label' and 'text' types as appropriate for translatable things to make your settings translatable.

Honestly looking at your configuration schema, I am not sure what makes sense to make translatable?! Think expose on localize.drupal.org/locale module. There does not seem to be user facing labels or descriptions and things like that... Not sure what is there to translate. (Once again this feature is not designed to support per-language settings).

hass’s picture

Now, after adding translatable: true I get a form.

[schema]

  account:
      type: string
      label: 'Web Property ID'
      translatable: true

I'm finally confused... will POTX extract the default setting value of translatables from install/google_analytics.yml and import them to l.d.o for translation or not?

Let's say something I really do not like to see on l.d.o would be visibility.pages value if I enable translatable:

visibility:
  pages: "admin\nadmin/*\nbatch\nnode/add*\nnode/*/*\nuser/*/*"

In previous versions of GA I have added account to variables module and allowed translation of this. This makes sense if you run one UA codes per site language. I believe there are more settings that may be useful.

hass’s picture

And this code change is something core translation module should add automatically I think. Otherwise we need to teach every developer who enable a translatable strings to not forget adding a module_local_task.yml to the module.

gábor hojtsy’s picture

#12: we manually added default tabs to core at #2095271: Add default tabs for routes expected by config_translation and have #2095117: Menu system should provide a default tab if none exists open where you can help make this automation happen. I agree it would be good.

#11: as I said at least 2 times on this issue, this feature is designed for locale/l.d.o translatability not separate values per language. What you are trying to do is not what feature was designed to do.

hass’s picture

Category: Bug report » Support request
Status: Active » Fixed

Well, I may need to use what exists. I strongly believe we need per language configurations like we had a need for them in past. What has been implemented already may not the intended use case, but it looks like a working solution to me. I guess we need a new issue to close the lack of feature and I opened #2275865: Per language settings (vs translated settings) are not directly supported for this. However I think we have everything in place already, we only need to tell POTX not to extract these translatable strings to l.d.o. This extractor is not yet done as I know from a different case.

I'm closing this case for now as your support helped me getting the issue resolved. I opened some individual issues for the things I learned here.

or should we keep this case open here and change the misleading access denied message to a more useful message?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.