Merge pull request #11833 from AllForNothing/i18n-2

Improve i18n service
This commit is contained in:
Will Sun 2020-05-07 11:45:30 +08:00 committed by GitHub
commit 8331703eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 4 deletions

View File

@ -25,6 +25,7 @@ COPY src/portal /build_dir
ENV NPM_CONFIG_REGISTRY=${npm_registry}
RUN npm install --unsafe-perm
RUN npm run generate-build-timestamp
RUN node --max_old_space_size=2048 'node_modules/@angular/cli/bin/ng' build --prod
FROM ${harbor_base_namespace}/harbor-portal-base:${harbor_base_image_version}

View File

@ -19,7 +19,8 @@
"build": "ng build --aot",
"release": "ng build --prod",
"build-mock-api-server": "tsc -p server",
"mock-api-server": "npm run build-mock-api-server && node server/dist/server/src/mock-api.js"
"mock-api-server": "npm run build-mock-api-server && node server/dist/server/src/mock-api.js",
"generate-build-timestamp": "node scripts/generate-build-timestamp.js"
},
"private": true,
"dependencies": {

View File

@ -0,0 +1,19 @@
/**
* generate timestamp for each production build
*/
const fs = require('fs');
const data = fs.readFileSync('src/environments/environment.prod.ts', 'utf8').split('\n');
let buildTimestampIndex = 0;
data.forEach((item,index) => {
if(item.indexOf('buildTimestamp') !== -1) {
buildTimestampIndex = index;
}
});
if (buildTimestampIndex > 0) {
const timestamp = new Date().getTime();
data[buildTimestampIndex] = ` buildTimestamp: ${timestamp},`;
fs.writeFileSync('src/environments/environment.prod.ts', data.join('\n'), 'utf8');
}

View File

@ -12,5 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
export const environment = {
production: true
production: true,
buildTimestamp: 0,
};

View File

@ -17,5 +17,6 @@
// The list of which env maps to which file can be found in `angular-cli.json`.
export const environment = {
production: false
production: false,
buildTimestamp: 0,
};

View File

@ -11,11 +11,15 @@ import { TranslateHttpLoader } from "@ngx-translate/http-loader";
import { MyMissingTranslationHandler } from "../../i18n/missing-trans.handler";
import { TranslatorJsonLoader } from "../../i18n/local-json.loader";
import { ClipboardModule } from "../../components/third-party/ngx-clipboard";
import { environment } from '../../../environments/environment';
export function GeneralTranslatorLoader(http: HttpClient, config: IServiceConfig) {
if (config && config.langMessageLoader === 'http') {
let prefix: string = config.langMessagePathForHttpLoader ? config.langMessagePathForHttpLoader : "i18n/lang/";
const prefix: string = config.langMessagePathForHttpLoader ? config.langMessagePathForHttpLoader : "i18n/lang/";
let suffix: string = config.langMessageFileSuffixForHttpLoader ? config.langMessageFileSuffixForHttpLoader : "-lang.json";
if (environment && environment.buildTimestamp) {
suffix += `?buildTimeStamp=${environment.buildTimestamp}`;
}
return new TranslateHttpLoader(http, prefix, suffix);
} else {
return new TranslatorJsonLoader(config);