Firebase 托管不显示本地化构建

Firebase Hosting not showing localized build

我想在 http://myapp.com/en/ and Japanese under http://myapp.com/ja/ 下默认使用英语。 但两者都以英文显示(默认)。我已经更改,因此它应该重写 firebase.json 文件中的 dorrect 语言文件夹,还将 i18n 根目录添加到与语言文件夹相同的位置(见下文)。

我已经在我的本地计算机上测试了服务和翻译工作,但在 prod (firebase) 部署之后没有。

在我的 angular.json 文件中它看起来像这样。

 "i18n": {
    "sourceLocale": {
      "code": "en",
      "baseHref": "en"
    },
    "locales": {
      "ja": {
        "translation": "src/locale/messages.ja.xlf",
        "baseHref": "ja"
      }
    }
  },

当我发球时,它在本地运作良好。或 ng serve --configuration="ja"。我的发球在 angular.json.

中看起来像这样
    "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": {
      "browserTarget": "myapp:build"
    },
    "configurations": {
      "production": {
        "browserTarget": "myapp:build:production"
      },
      "ja": {
        "browserTarget": "myapp:build:ja"
      }
    }
  },

现在,当我构建时,我会这样做。 ng build --prod --localize 我尝试使用 aot=disabled 来查看它是否有任何不同,但没有。

从 angular.json 构建看起来像这样。

"build": {
    "localize": true,
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "outputPath": "dist/myapp",
      "index": "src/index.html",
      "main": "src/main.ts",
      "polyfills": "src/polyfills.ts",
      "tsConfig": "tsconfig.app.json",
      "aot": true,
      "assets": [
        "src/favicon.ico",
        "src/assets"
      ],
      "styles": [
        "src/styles.css",
        "./node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],
      "scripts": [
        "./node_modules/jquery/dist/jquery.min.js",
        "./node_modules/popper.js/dist/umd/popper.min.js",
        "./node_modules/bootstrap/dist/js/bootstrap.min.js"
      ]
    },
    "configurations": {
      "ja": {
        "localize": [
          "ja"
        ]
      },
      "production": {
        "fileReplacements": [
          {
            "replace": "src/environments/environment.ts",
            "with": "src/environments/environment.prod.ts"
          }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": false,
        "budgets": [
          {
            "type": "initial",
            "maximumWarning": "2mb",
            "maximumError": "5mb"
          },
          {
            "type": "anyComponentStyle",
            "maximumWarning": "6kb",
            "maximumError": "10kb"
          }
        ]
      }
    }
  },

现在我的 firebase.json 看起来像这样:

    {
    "hosting": {
      "public": "./dist/myapp",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "rewrites": [
        {
          "source": "/ja/**",
          "destination": "/ja/index.html"
        },
        {
          "source": "/en/**",
          "destination": "/en/index.html"
        }
      ],
      "i18n": {
        "root": "/"
      }
    }
  }

所以我可以在 /en/ 和 /ja/ 访问应用程序,但 ja 没有翻译。关于我做错了什么的任何指示比我最近认为您应该将 localize 文件夹放在单独的文件夹和根文件夹中?通过这些设置,我觉得它应该可以工作,但显然有些地方不对。

删除

"baseHref": "en" 

"baseHref": "ja" 

来自 i18n 下的 angular.json 文件使其工作!我误解了 baseHref 的作用!