如何使用单个服务工作者启用多语言 Angular PWA 的安装? [英] How to enable installation of the multi language Angular PWA with single service worker?

查看:30
本文介绍了如何使用单个服务工作者启用多语言 Angular PWA 的安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备了具有本地化语言版本的应用程序.为此,我使用了原生 Angular i18n 模块,该模块准备了两个应用程序包,每个包都使用适当的语言.

I have prepared applications with localized language versions. For this purpose I used the native Angular i18n module, which prepared two application packages with the appropriate language in each.

应用程序的每个版本都在我的 nginx 服务器上的各个位置下可用:

Each version of the application is available under the individual location on my nginx server:

  • myapp.com/en/...
  • myapp.com/pl/...

我希望我的应用程序安装一次作为 PWA 并使用(单个?)服务工作者提供两种语言版本.

I would like my application to be installed once as PWA and provide both language versions using a (single?) service worker.

不幸的是,我现在使用 @angular/pwa 模块所能做的就是为每个应用程序提供一个单独的服务工作者,这会强制我的应用程序的每种语言版本都单独安装.

Unfortunately all I could do now with @angular/pwa module is to provide a separate service workers for each application, which forces separate installations of each language version of my application.

我的问题是:有什么方法可以让应用程序按照我使用 @angular/pwa 或 Workbox 描述的方式工作?

My question is: Is there any way for the application to work in the way I described using @angular/pwa or Workbox?

//顺便说一句,Angular 的创建者没有强调@angular/localize 与@angular/pwa 的集成,这有点令人惊讶.

// By the way, it's a bit surprising that the creators of Angular didn't highlight the integration of @angular/localize with @angular/pwa.

推荐答案

对于每种语言,您都有 N 个应用程序.它们托管在不同的域上.它们实际上是不同的应用程序.因此,即使您将所有这些都安装在一个 URL 中,您也可以安装所有这些.

You have N apps for each language. They are hosted on different domains. They are actually different apps. Therefore even if you install all of them in one URL you get to install all of them.

作为将一个域用于不同应用程序的一种选择,您可以创建一个包含所有语言及其相应 JS 文件的配置,或者为 index.html 创建一个解析器.然后,您需要创建您自己的工作程序,它将在页面加载时插入正确的脚本(您不能随时执行此操作,因为 JS 代码已经加载).这将加载适当的应用程序.我猜每个应用都有你的工作人员.

As an option of using one domain with different apps you could either create a config with all langs and their corresponding JS files, or make a parser for index.html. Then, you need to create your own worker which will insert the right scripts on page load (you can't do it on go since JS code would be already loaded). This will load the appropriate app. And there you have your workers for each app included I guess.

如果您要将 i18n 工具作为混合应用发布到 Google 商店中,您可能需要考虑更换它.

You may want to consider switching your i18n tool if you are about publishing it in Google Store as a hybrid app.

作为另一种选择,您可以为 WebView 提供一个层,并根据用户选择的语言加载不同的 URL.

As another option you could provide a layer for your WebView and load different URL depending on language user's chosen.

这篇关于如何使用单个服务工作者启用多语言 Angular PWA 的安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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