Add proper multilingual support for the manifest.json

Created on 21 August 2023, 10 months ago
Updated 13 September 2023, 10 months ago

Problem/Motivation

There is currently a 'lang' option on the configuration page. This option currently doesn't do anything and manifest.json's do not support multilinguality.
But, since we dynamically create our manifest.json through code, we can also dynamically change its content based on the currently selected language.

For example, if our site has the prefix '/de/' for the german version and '/en/' for the english version, we need to dynamically apply those prefixes to the 'start_url' and 'scope' paths.
The main problem is, that we also have settings for those as manifest entries. So if we enable 'translatability' we need to figure out, how to apply the language prefixes to our existing settings, or if we simply grey them out and use our own logic, if it is enabled.
To select the language for the manifest.json, we should use a similar logic to the 'language_configuration' form element provided by Drupal's 'language' module:

Leaving out 'not applicable' and 'not specified'.

Steps to reproduce

Proposed resolution

Add proper multilingual support for the manifest.json.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    Wouldn't this simply mean to make the config values translatable and add the config translation form for such values?
    And then use these values for the different paths?

    Anyway I'm still not sure how to handle manifest.jsons for such cases correctly in general. Perhaps we should take a look at large multilang websites providing manifest.jsons?

  • 🇩🇪Germany Grevil

    Great idea! No idea, why I didn't think of this...

  • 🇩🇪Germany Grevil

    But we should make clear to the user, that the translation of both "scope" and "start_url" needs to specify the website's language paths. As well as a few other config values. We should really carefully look over each config entry and check if and how a translated value could look like.

  • 🇩🇪Germany Anybody Porta Westfalica

    Yeah, I think this is an indeed complex and complicated issue we should handle with care. No quick shots.

  • 🇩🇪Germany Grevil

    Ok I did some researching and these are my thoughts on the config keys to translate:

    Manifest Settings:

    • site_name => Yes
    • short_name => Yes
    • description => Yes
    • categories => Might eventually make sense, there is a list of known categories here: https://www.w3.org/TR/manifest-app-info/#categories-member, but users might want to add language specific categories? Lets further discuss this.
    • start_url => Yes, translation could have the different site language prefixes (e.g. "/en" or "mypwa/de").
    • scope => Yes, translation could have the different site language prefixes (e.g. "/en" or "mypwa/de").
    • lang => Remove this config entirely.
    • theme_color => No
    • background_color => No
    • display => No
    • orientation => No
    • default_image => No
    • cross_origin => No

    Service Worker Settings:

    • urls_to_cache => Needs further discussion. Currently, these urls are already language prefixed through our serviceworker.js (specifically through "getLanguagePathPrefix()"). BUT It seems like the logic there won't do anything, if the response is prefixed with something like 'myApp/en', since it uses url.pathname.startsWith(`/${langcode}`) to specify the used langcode.
    • urls_to_exclude => Needs further discussion, see above.
    • offline_page => Yes, translation could have the different site language prefixes (e.g. "/en" or "mypwa/de").
    • cache_version => No
    • skip_waiting => No

    At first look, what do you think about this @Anybody?

  • 🇩🇪Germany Anybody Porta Westfalica

    Re:

    • categories No translation, as it's always EN (technical name)
    • lang => Remove this config entirely. => I don't think so, as this might be important for the client. Perhaps we should return the Drupal language value by default, if no value entered, but allow to override the automatism by entering an overwrite string (translatable)?
    • urls_to_cache => No (only makes things harder and the list can just be merged)
    • urls_to_exclude => No (same as above)

    Totally agree with the rest!

  • 🇩🇪Germany Grevil

    lang => Remove this config entirely. => I don't think so

    I digress. "lang" isn't used anywhere in the module. But WAIT! This is really unusual... I just wanted to comment, that "lang" is NOT a valid manifest.json member, but it actually is! But for some reason it is only specified in https://www.w3.org/TR/appmanifest/#lang-member but not listed on the mdn page: https://developer.mozilla.org/en-US/docs/Web/Manifest. That is really weird... But I guess we should trust the w3c standard? But I am wondering, if this is even properly implemented for most modern browsers, if it isn't listed as a valid key in the mdn docs...

    Furthermore, we should take a look at https://www.w3.org/TR/appmanifest/#dir-member, which is ALSO not listed on the mdn docs... need feedback on this.

    I forgot we can use the asterisk inside "urls_to_cache", so I agree, "NO" would be better. BUT we should change the getLanguagePathPrefix() implementation.

  • 🇩🇪Germany Anybody Porta Westfalica

    Re #8 then I think for now, just make it optional and translatable, so the user can chose to leave it out. Perhaps also add an according descrption. We shouldn't get blocked by that confusing thing, I think. We can improve things later, if it's needed.

  • 🇩🇪Germany Anybody Porta Westfalica

    PS: But please add an example and link to https://www.w3.org/TR/appmanifest/#lang-member
    otherwise it might be unclear which format is expected.

  • 🇩🇪Germany Grevil

    Re #8 then I think for now, just make it optional and translatable, so the user can chose to leave it out

    There currently isn't a form element for 'lang' and the config entry isn't used. I'd say we remove it for now. We can reintroduce it later if needed.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • @grevil opened merge request.
  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    All done. I am unsure, if we need to add functionality to the update hook, since a few of these configs were originally translatable.

    Furthermore, do we need any description changes? What do you think @Anybody? Please review for now.

  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Nice, left some final comments.

    Especially see #8 abd #9 I guess we had a misunderstanding there.

    Re #13 no I think we can leave it as-is.

  • 🇩🇪Germany Anybody Porta Westfalica

    As just discussed, please also add "dir" with "ltr" as default.

    It's just a simple select for the text direction (left to right vs. right to left). For most parts of the world it's ltr. Let's make it a simple select option.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    1 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    1 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    All done, please review once again.

  • 🇩🇪Germany Grevil

    Not sure about not setting a default value for "dir", but not one for "lang", as they are really tidely coupled.

  • 🇩🇪Germany Anybody Porta Westfalica

    dir=ltr should be fine, I think. Let's take that one. Also makes sense, as it's a select. But yes, you can also leave it empty, as it's an optional setting anyway. Throw a dice ;)

  • 🇩🇪Germany Anybody Porta Westfalica

    Sorry, setting "auto" is correct. Just had a look into the specification!

  • Status changed to RTBC 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil nice work! Just one last documentation fix!

    All other things are RTBC, once tested manually!

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • Status changed to Needs work 10 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Remove the unnecessary "fromUri" calls, please rereview!

  • Assigned to Grevil
  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Left a comment!

    Furthermore, are'nt we missing the config_translation.yml for the appropriate UI?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • 🇩🇪Germany Grevil

    @Anybody, you are right!

    missing target="_blank"

    Unsure about implicitly using target="blank" here. The user can easily decide himself I think.

  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Never mind, the config_translation.yml already exists and I don't like the implicit "_blank" call, so setting this back to need review.

  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Explicit "_blank" call totally makes sense to external and especially doc URLs. Discarding the current tab for that is just bad UX. Please add it.

    config_translation.yml already existed, nice indeed!

    So just the _blank thing, then we're fine!

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Done, please review!

  • Issue was unassigned.
  • Status changed to RTBC 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Perfect! :)

  • Status changed to Fixed 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024