如何在 Google App Engine 上部署 Angular 多语言应用程序

How to deploy Angular multilanguage application on Google App Engine

我已经构建了我的 Angular 8 应用程序,其中包含 angular/clii18n multilanguage support(带有英语、西班牙语和法语的翻译)。

这样我就可以多次构建我的应用程序,每种语言一个,构建保存在 dist/my-app/endist/my-app/esdist/my-app/fr 等...

现在我想在 Google App Engine 上部署我的应用程序,但我不明白我应该如何 do/configure 部署我的应用程序的所有 lang 特定版本。

我已经在 GAE 上发布了我的默认(英文)版本并且它可以工作,但我不知道 how/where 部署所有其他版本(es、fr 等)。

我应该使用调度文件吗?你最好的方法是什么?

谢谢!

您可以将 dist/my-app 视为 AppEngine 的根文件夹。

  • 在此文件夹中添加一个 index.html(根据浏览器偏好或让用户选择重定向到默认区域设置)。
  • 在 GAE 中将整个文件夹部署为一个应用程序。
  • 每个本地化的应用程序将 sub-folders,然后由 GAE 作为 https:///xxxx.appspot.com/en/...

要构建具有多个语言环境的多个应用程序,请选中 Angular official docs

每个 href 都应设置为语言环境:

"baseHref": "/en/",

然后,更新 app.yaml 和处理程序以服务所有 sub-folders。

例如,这应该是这样的:

handlers:
- url: /fr/(.+)
  static_files: app/fr/index.html
  upload: app/fr/index.html
- url: /en/(.+)
  static_files: app/en/index.html
  upload: app/en/index.html
- url: /(.+)
  static_files: app/index.html
  upload: app/index.html
- url: /
  static_files: app/index.html
  upload: app/index.html

但我不是处理程序正则表达式的专家,所以我敢肯定它可以优化。

部署文件夹应如下所示:

deploy
  app.yaml
  app
    index.html // page to propose user to select locale or auto redirect
    fr
      index.html
      bundles.js...
    en
      index.html
      bundles.js...