Commit 90e34e01 authored by AllForNothing's avatar AllForNothing
Browse files

Improve i18n service


Signed-off-by: default avatarAllForNothing <sshijun@vmware.com>
parent 54fe00d1
......@@ -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}
......
......@@ -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": {
......
/**
* 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');
}
......@@ -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,
};
......@@ -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,
};
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment