本地化PWA Web清单 [英] Localising a PWA web manifest

本文介绍了本地化PWA Web清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以本地化Web清单?即具有namedescription等的多种翻译形式...

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...

根据url(example.com/en/foo)中的语言环境,加载相对清单.

Dependant on the locale in the url (example.com/en/foo), load the relative manifest.

例如:

  • 对于example.com/en/foo,加载example.com/en/manifest.json
  • 对于example.com/jp/foo,加载example.com/jp/manifest.json
  • For example.com/en/foo, load example.com/en/manifest.json
  • For example.com/jp/foo, load example.com/jp/manifest.json

缺点

  • 我不认为这会真正起作用,因为每个网站只能显示一个清单(据我所知),而且我相当确定它必须位于根目录中.
  • 即使有可能,鉴于我的应用程序是静态托管的SPA,我也不完全确定如何实现它,即在浏览器加载清单之前,我无法动态更新清单的链接. .也许我可以加载相对于URI的清单,但不能100%地确定这会起作用

托管PWA的多个版本(子域或TLD)...例如:

Host multiple versions of the PWA (either subdomain or TLD)... For example:

  • en.example.com/example.com
  • jp.example.com/example.jp
  • 等...
  • en.example.com/example.com
  • jp.example.com/example.jp
  • etc...

鉴于清单是由构建过程生成的,因此通过在管道中添加多个部署步骤,实际上很容易实现.然后,我将针对每个部署使用环境变量来确定要插入清单中的文本.

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.

缺点

  • 无法切换应用的语言(这是客户端的一项非常重要的功能)
  • 不管实现起来有多么容易",它似乎都不正确

推荐答案

W3C文档中关于网络清单,我发现了以下内容:

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:

  • 动态设置语言: 例如,这可以包括询问最终用户其首选语言是什么,并基于该语言首选项(例如,使用类似"manifest.php?lang = fr"的URL)向该文档动态添加或替换清单链接关系. ).
  • 在服务器上使用内容协商或地理定位等: 托管Web应用程序的服务器可以尝试通过使用地理位置定位或使用内容协商(例如,使用[RFC7540]的"Accept-Language"标头,甚至是自定义HTTP标头)来预定最终用户的语言.
  • 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.

目前在Github上有一个公开请求.具体来说,此链接与W3C网站上的建议相符.

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提供了更实用的指南来本地化清单文件,也许可以用作网络清单的指南.

Google provide a more practical guide to localize the manifest file and maybe can be used as guide for the web manifest.

更新

您可以为您的index.html创建一个小脚本吗?

Could you create a small script for your index.html?

您不需要php,而只需Vanilla JS(如果您可以控制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">

这篇关于本地化PWA Web清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆