mirror of
https://github.com/goharbor/harbor
synced 2025-05-21 20:26:38 +00:00
Merge pull request #11833 from AllForNothing/i18n-2
Improve i18n service
This commit is contained in:
commit
8331703eb3
@ -25,6 +25,7 @@ COPY src/portal /build_dir
|
|||||||
|
|
||||||
ENV NPM_CONFIG_REGISTRY=${npm_registry}
|
ENV NPM_CONFIG_REGISTRY=${npm_registry}
|
||||||
RUN npm install --unsafe-perm
|
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
|
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}
|
FROM ${harbor_base_namespace}/harbor-portal-base:${harbor_base_image_version}
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
"build": "ng build --aot",
|
"build": "ng build --aot",
|
||||||
"release": "ng build --prod",
|
"release": "ng build --prod",
|
||||||
"build-mock-api-server": "tsc -p server",
|
"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,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
19
src/portal/scripts/generate-build-timestamp.js
Normal file
19
src/portal/scripts/generate-build-timestamp.js
Normal 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -12,5 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
export const environment = {
|
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`.
|
// The list of which env maps to which file can be found in `angular-cli.json`.
|
||||||
|
|
||||||
export const environment = {
|
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 { MyMissingTranslationHandler } from "../../i18n/missing-trans.handler";
|
||||||
import { TranslatorJsonLoader } from "../../i18n/local-json.loader";
|
import { TranslatorJsonLoader } from "../../i18n/local-json.loader";
|
||||||
import { ClipboardModule } from "../../components/third-party/ngx-clipboard";
|
import { ClipboardModule } from "../../components/third-party/ngx-clipboard";
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
|
||||||
export function GeneralTranslatorLoader(http: HttpClient, config: IServiceConfig) {
|
export function GeneralTranslatorLoader(http: HttpClient, config: IServiceConfig) {
|
||||||
if (config && config.langMessageLoader === 'http') {
|
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";
|
let suffix: string = config.langMessageFileSuffixForHttpLoader ? config.langMessageFileSuffixForHttpLoader : "-lang.json";
|
||||||
|
if (environment && environment.buildTimestamp) {
|
||||||
|
suffix += `?buildTimeStamp=${environment.buildTimestamp}`;
|
||||||
|
}
|
||||||
return new TranslateHttpLoader(http, prefix, suffix);
|
return new TranslateHttpLoader(http, prefix, suffix);
|
||||||
} else {
|
} else {
|
||||||
return new TranslatorJsonLoader(config);
|
return new TranslatorJsonLoader(config);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user