localization - 本地化 PWA Web list

标签 localization internationalization single-page-application progressive-web-apps workbox

有没有办法本地化 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

  • 缺点
  • 我不相信这实际上会起作用,因为每个网站只能有一个 list (据我所知),而且我相当确定它需要在根
  • 中。
  • 即使这是可能的,鉴于我的应用程序是一个静态托管的 SPA,我不完全确定我将如何实现它,即我无法在浏览器加载 list 之前动态更新 list 的链接。也许我可以加载相对于 URI 的 list ,但不能 100% 确定这会起作用

  • 潜在解决方案 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/

    相关文章:

    javascript - 未捕获的 TypeError : Cannot set property 'app' of undefined Vue. js

    java - 如何使用 java Spark 为 SPA 实现捕获所有路由

    node.js - 如何模块化 AngularJS 应用程序/插件

    javascript - 时区 : user preference vs client-side Javascript

    ruby-on-rails - rails 5 : How Do I Get My Error Pages in the Public Folder for Different Locales to Display Other than "en?

    javascript - Jquery - 创建一个通用语言文件来声明任何插件的默认值

    email - 交响乐 1.4 : How to send i18n mail to a user who is not the current user (different culture)

    c# - 使用 Core 2.2 本地化的 Razor 页面不起作用

    c# - Visual Studio 2010 - 更改语言属性

    c# - WinForms 动态本地化