Skip to content

Commit

Permalink
Merge pull request #437 from geonetwork/fix-i18n-1.0.x
Browse files Browse the repository at this point in the history
Fix i18n (v1.0.1): Let util-18n.module handle language detection
  • Loading branch information
tkohr authored Mar 21, 2023
2 parents e5cce56 + 3af42f4 commit 0cec465
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 40 deletions.
10 changes: 2 additions & 8 deletions apps/datafeeder/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { UploadDataComponent } from './presentation/components/upload-data/upload-data.component'
import {
getDefaultLang,
getLangFromBrowser,
TRANSLATE_DEFAULT_CONFIG,
UtilI18nModule,
} from '@geonetwork-ui/util/i18n'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { UploadDataPageComponent } from './presentation/pages/upload-data-page/upload-data.page'
import { UploadDataRulesComponent } from './presentation/components/upload-data-rules/upload-data-rules.component'
import { HttpClientModule } from '@angular/common/http'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { TranslateModule } from '@ngx-translate/core'
import { DatasetValidationPageComponent } from './presentation/pages/dataset-validation-page/dataset-validation-page'
import { DataImportValidationMapPanelComponent } from './presentation/components/data-import-validation-map-panel/data-import-validation-map-panel.component'
import { AnalysisProgressPageComponent } from './presentation/pages/analysis-progress-page/analysis-progress.page'
Expand Down Expand Up @@ -84,8 +82,4 @@ export function apiConfigurationFactory() {
],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(translate: TranslateService) {
translate.use(getLangFromBrowser() || getDefaultLang())
}
}
export class AppModule {}
12 changes: 2 additions & 10 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
getThemeConfig,
} from '@geonetwork-ui/util/app-config'
import {
getDefaultLang,
getLangFromBrowser,
TRANSLATE_DEFAULT_CONFIG,
UtilI18nModule,
} from '@geonetwork-ui/util/i18n'
Expand All @@ -43,7 +41,7 @@ import { LOGIN_URL } from '@geonetwork-ui/feature/auth'
import { EffectsModule } from '@ngrx/effects'
import { MetaReducer, StoreModule } from '@ngrx/store'
import { StoreDevtoolsModule } from '@ngrx/store-devtools'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { TranslateModule } from '@ngx-translate/core'
import { filter } from 'rxjs/operators'
import { environment } from '../environments/environment'

Expand Down Expand Up @@ -165,13 +163,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : []
bootstrap: [AppComponent],
})
export class AppModule {
constructor(
translate: TranslateService,
router: Router,
@Inject(DOCUMENT) private document: Document
) {
translate.setDefaultLang(getDefaultLang())
translate.use(getLangFromBrowser() || getDefaultLang())
constructor(router: Router, @Inject(DOCUMENT) private document: Document) {
ThemeService.applyCssVariables(
getThemeConfig().PRIMARY_COLOR,
getThemeConfig().SECONDARY_COLOR,
Expand Down
11 changes: 2 additions & 9 deletions apps/search/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { FeatureMapModule } from '@geonetwork-ui/feature/map'
import { UiLayoutModule } from '@geonetwork-ui/ui/layout'
import { UiMapModule } from '@geonetwork-ui/ui/map'
import {
getDefaultLang,
UtilI18nModule,
TRANSLATE_GEONETWORK_CONFIG,
} from '@geonetwork-ui/util/i18n'
Expand All @@ -16,7 +15,7 @@ import { FeatureSearchModule } from '@geonetwork-ui/feature/search'
import { EffectsModule } from '@ngrx/effects'
import { MetaReducer, StoreModule } from '@ngrx/store'
import { StoreDevtoolsModule } from '@ngrx/store-devtools'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { TranslateModule } from '@ngx-translate/core'
import { storeFreeze } from 'ngrx-store-freeze'
import { environment } from '../environments/environment'
import { AppRoutingModule } from './app-routing.module'
Expand Down Expand Up @@ -57,10 +56,4 @@ export const metaReducers: MetaReducer<any>[] = !environment.production
],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(translate: TranslateService) {
const lang = getDefaultLang()
translate.setDefaultLang(lang)
translate.use(lang)
}
}
export class AppModule {}
13 changes: 1 addition & 12 deletions libs/util/i18n/src/lib/i18n.constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { HttpClient } from '@angular/common/http'
import { ToolsApiService } from '@geonetwork-ui/data-access/gn4'
import { TranslateCompiler, TranslateLoader } from '@ngx-translate/core'
import { TranslateHttpLoader } from '@ngx-translate/http-loader'
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'
import { Gn4TranslateLoader } from './gn4.translate.loader'
import { map } from 'rxjs/operators'
import { FileTranslateLoader } from './file.translate.loader'

export const DEFAULT_LANG = 'en'
Expand Down Expand Up @@ -37,19 +35,10 @@ export const LANG_2_TO_3_MAPPER = Object.entries(LANG_3_TO_2_MAPPER).reduce(
export function HttpLoaderFactory(http: HttpClient) {
return new FileTranslateLoader(http, './assets/i18n/')
}

export function getLangFromHtml() {
const html: HTMLElement = document.getElementsByTagName('html')[0]
const lang = html.getAttribute('lang')
return lang.substr(0, 2)
}
//Deprecated, but currently still used in datafeeder
export function getLangFromBrowser() {
return navigator.language.substr(0, 2)
}
export function getDefaultLang() {
return getLangFromHtml() || 'en'
}

export const TRANSLATE_DEFAULT_CONFIG = {
compiler: {
provide: TranslateCompiler,
Expand Down
2 changes: 1 addition & 1 deletion libs/util/i18n/src/lib/util-i18n.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import { CommonModule } from '@angular/common'
export class UtilI18nModule {
constructor(translate: TranslateService) {
translate.setDefaultLang(DEFAULT_LANG)
translate.use(DEFAULT_LANG)
translate.use(translate.getBrowserLang() || DEFAULT_LANG)
}
}

0 comments on commit 0cec465

Please sign in to comment.