Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamically inject primelocale translations into libs after build #483

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ dist
.idea

.nx

libs/angular-accelerator/tmp/
libs/portal-integration-angular/tmp/
7 changes: 6 additions & 1 deletion libs/angular-accelerator/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"entryFile": "src/index.ts"
},
"assets": [
"./assets/**"
"./assets/**",
{
"input": "tmp/primelocale/",
"glob": "{en,de}.json",
"output": "assets/i18n/primeng"
}
]
}
14 changes: 14 additions & 0 deletions libs/angular-accelerator/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@
"tags": [],
"projectType": "library",
"targets": {
"copyPrimelocaleTranslations": {
"executor": "nx:run-commands",
"options": {
"commands": [
"mkdir -p libs/angular-accelerator/tmp/primelocale",
"cp node_modules/primelocale/de.json libs/angular-accelerator/tmp/primelocale/",
"cp node_modules/primelocale/en.json libs/angular-accelerator/tmp/primelocale/",
"sed -i 's/\"de\":/\"primeng\":/' libs/angular-accelerator/tmp/primelocale/de.json",
"sed -i 's/\"en\":/\"primeng\":/' libs/angular-accelerator/tmp/primelocale/en.json"
],
"parallel": false
}
},
"build": {
"executor": "@nx/angular:package",
"dependsOn": ["^build", "copyPrimelocaleTranslations"],
"outputs": [
"{workspaceRoot}/dist/{projectRoot}"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ describe('CreateTranslateLoader', () => {
})

describe('without TranslationCache parameter', () => {
it('should call httpClient get 3 times if a remoteBaseUrl is set and if global loading is finished', (done) => {
it('should call httpClient get 4 times if a remoteBaseUrl is set and if global loading is finished', (done) => {
currentMfe$ = of({ remoteBaseUrl: 'remoteUrl' })
globalLoading$ = of(false)
const translateLoader = environmentInjector.runInContext(() =>
createTranslateLoader(httpClientMock, <AppStateService>(<unknown>appStateServiceMock))
)

translateLoader.getTranslation('en').subscribe(() => {
expect(httpClientMock.get).toHaveBeenCalledTimes(3)
expect(httpClientMock.get).toHaveBeenCalledTimes(4)
done()
})
})
Expand All @@ -60,7 +60,7 @@ describe('CreateTranslateLoader', () => {
})

describe('with TranslationCache parameter', () => {
it('should call httpClient get 3 times if a remoteBaseUrl is set and if global loading is finished', (done) => {
it('should call httpClient get 4 times if a remoteBaseUrl is set and if global loading is finished', (done) => {
currentMfe$ = of({ remoteBaseUrl: 'remoteUrl' })
globalLoading$ = of(false)
const translateLoader = createTranslateLoader(
Expand All @@ -70,7 +70,7 @@ describe('CreateTranslateLoader', () => {
)

translateLoader.getTranslation('en').subscribe(() => {
expect(httpClientMock.get).toHaveBeenCalledTimes(3)
expect(httpClientMock.get).toHaveBeenCalledTimes(4)
done()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export function createTranslateLoader(
Location.joinWithSlash(currentMfe.remoteBaseUrl, `onecx-portal-lib/assets/i18n/`),
'.json'
),
// Primelocale Translations
new CachingTranslateLoader(
ts,
http,
Location.joinWithSlash(currentMfe.remoteBaseUrl, `onecx-portal-lib/assets/i18n/primeng/`),
'.json'
),
// translations of the app
new CachingTranslateLoader(
ts,
Expand Down
5 changes: 5 additions & 0 deletions libs/portal-integration-angular/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"input": "src/lib/core/directives",
"glob": "**/*.scss",
"output": "assets"
},
{
"input": "tmp/primelocale/",
"glob": "{en,de}.json",
"output": "assets/i18n/primeng"
}
]
}
14 changes: 14 additions & 0 deletions libs/portal-integration-angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@
"tags": [],
"projectType": "library",
"targets": {
"copyPrimelocaleTranslations": {
"executor": "nx:run-commands",
"options": {
"commands": [
"mkdir -p libs/portal-integration-angular/tmp/primelocale",
"cp node_modules/primelocale/de.json libs/portal-integration-angular/tmp/primelocale/",
"cp node_modules/primelocale/en.json libs/portal-integration-angular/tmp/primelocale/",
"sed -i 's/\"de\":/\"primeng\":/' libs/portal-integration-angular/tmp/primelocale/de.json",
"sed -i 's/\"en\":/\"primeng\":/' libs/portal-integration-angular/tmp/primelocale/en.json"
],
"parallel": false
}
},
"build": {
"executor": "@nx/angular:package",
"dependsOn": ["^build", "copyPrimelocaleTranslations"],
"outputs": [
"{workspaceRoot}/dist/{projectRoot}"
],
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"ngx-color": "^9.0.0",
"primeflex": "^3.3.1",
"primeicons": "^7.0.0",
"primelocale": "^1.0.3",
"primeng": "17.18.8",
"rxjs": "7.8.1",
"storybook": "^8.3.1",
Expand Down
Loading