Is there a way in which a web manifest can be localised? i.e. having multiple translations of name
, description
etc...
I have thought of a couple of potential solutions but they each have pretty big drawbacks...
Dependant on the locale in the url (example.com/en/foo
), load the relative manifest.
For example:
example.com/en/foo
, load example.com/en/manifest.json
example.com/jp/foo
, load example.com/jp/manifest.json
Drawbacks
Host multiple versions of the PWA (either subdomain or TLD)... For example:
en.example.com
/example.com
jp.example.com
/example.jp
Given the manifest is generated by the build process, this would actually be very easy to implement by adding multiple deploy steps to the pipelines. I would then use the environment variables for each deployment to determine the text to be inserted into the manifest.
Drawbacks
The manifest can include basic information such as the app's name, icon, and theme color; advanced preferences, such as desired orientation and app shortcuts; and catalog metadata, such as screenshots. A web app manifest is a required installability criteria in every browser. Your PWA will not install without it.
Learn PWA! The web app manifest is a JSON file that defines how the PWA should be treated as an installed application, including the look and feel and basic behavior within the operating system. The web app manifest is a file you create that tells the browser how you want your web content to display as an app in the operating system.
In the screen shot above, for example, the app has a tiny Firefox icon, indicating that it's a web app that uses the Firefox runtime. In some browsers, a splash screen is also generated from the information in the manifest, which is shown when the PWA is launched and while it's being loaded started up.
The PWA can be referenced on some app stores such as the Windows Store . The PWA can be displayed in full screen or in a standalone window, without the browser UI. The manifest is a JSON file that contains several properties. It is recommended to fill in most of them to optimize the discovery and the experience of the PWA.
On the W3C document about the web manifest, I found the following:
It is expected that authors will localize the content of a manifest by using one of the following options:
- Dynamically setting the language: This can include, for instance, asking the end-user what their preferred language is and dynamically adding or replacing the manifest link relationship to the document based on that language preference (e.g., using a URL like "manifest.php?lang=fr").
- Using content-negotiation, or geotargeting, etc. on the server: The server that hosts the web application could attempt to predetermine the end-user's language by using geotargeting or by using content negotiation (e.g., using [RFC7540]'s "Accept-Language" header, or even a custom HTTP header).
This though says what should be done, but not exactly how.
There is currently an open requests about it on Github. Specifically this link argues with the suggestion on W3C site.
I will update the answer with more details as soon as I gather more information.
Google provide a more practical guide to localize the manifest file and maybe can be used as guide for the web manifest.
UPDATE
Could you create a small script for your index.html
?
You do not need php, but simply Vanilla JS (if you have control over the index.html file) and load a specific manifest file according to the user locale.
<!-- If English is detected, the script will load this into the page -->
<link rel="manifest" href="/path.../en.manifest.json">
<!-- If French is detected, the script will load this instead -->
<link rel="manifest" href="/path.../fr.manifest.json">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With