有没有办法本地化 Web list ?即有多个 name
的翻译, description
等等...
我已经想到了几个潜在的解决方案,但它们每个都有很大的缺点......
潜在解决方案 1(首选但不确定它是否有效)
根据 url ( example.com/en/foo
) 中的区域设置,加载相关 list 。
例如:
example.com/en/foo
, 负载 example.com/en/manifest.json
example.com/jp/foo
, 负载 example.com/jp/manifest.json
缺点
潜在解决方案 2
托管多个版本的 PWA(子域或 TLD)...例如:
en.example.com
/example.com
jp.example.com
/example.jp
鉴于 list 是由构建过程生成的,这实际上很容易通过向管道添加多个部署步骤来实现。然后我将使用每个部署的环境变量来确定要插入到 list 中的文本。
缺点
最佳答案
关于 W3C document关于网络 list ,我发现了以下内容:
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).
这虽然说明了应该做什么,但不完全是如何做。
当前有一个 open requests about it在 Github 上。具体this link与 W3C 网站上的建议争论不休。
一旦我收集到更多信息,我将用更多细节更新答案。
谷歌提供more practical guide本地化 list 文件,也许可以用作网络 list 的指南。
更新
你能为你的
index.html
创建一个小脚本吗? ?您不需要 php,而只需要 Vanilla JS(如果您可以控制 index.html 文件)并根据用户区域设置加载特定的 list 文件。
<!-- 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">
关于localization - 本地化 PWA Web list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57763393/