mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 06:38:19 +01: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}
|
||||
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": {
|
||||
|
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
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user