【问题标题】:Firebase Hosting not showing localized buildFirebase 托管未显示本地化构建
【发布时间】:2020-10-05 12:09:04
【问题描述】:

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

我已经在本地计算机上测试了 serve 和翻译工作,但不是在 prod (firebase) 部署之后。

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

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

当我发球时,它在本地运行良好。或 ng 服务 --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 没有翻译。关于我做错了什么的任何指针比我最近的头要多,你应该将你的本地化文件夹放在一个单独的文件夹和根文件夹中?有了这些设置,我觉得它应该可以工作,但显然有问题。

【问题讨论】:

    标签: angular firebase internationalization firebase-hosting


    【解决方案1】:

    删除

    "baseHref": "en" 
    

    "baseHref": "ja" 
    

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

    【讨论】:

      猜你喜欢
      • 2021-09-21
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 2019-07-21
      • 2020-06-16
      相关资源
      最近更新 更多