-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #904 from gisaia/feat/map-translation
Add translation provided by arlas-map
- Loading branch information
Showing
6 changed files
with
85 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
projects/arlas-toolkit/src/lib/tools/Translation/custom-translate-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Gisaïa under one or more contributor | ||
* license agreements. See the NOTICE.txt file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Gisaïa licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import en from 'arlas-web-components/assets/i18n/en.json'; | ||
import es from 'arlas-web-components/assets/i18n/es.json'; | ||
import fr from 'arlas-web-components/assets/i18n/fr.json'; | ||
import enMap from 'arlas-map/assets/i18n/en.json'; | ||
import esMap from 'arlas-map/assets/i18n/es.json'; | ||
import frMap from 'arlas-map/assets/i18n/fr.json'; | ||
import { TranslateLoader } from '@ngx-translate/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
|
||
export class CustomTranslateLoader implements TranslateLoader { | ||
|
||
public constructor(private readonly http: HttpClient) { } | ||
|
||
public getTranslation(lang: string): Observable<any> { | ||
const apiAddress = 'assets/i18n/' + lang + '.json?' + Date.now(); | ||
return new Observable(observer => { | ||
this.http.get(apiAddress).subscribe( | ||
res => { | ||
let merged = res; | ||
// Properties in res will overwrite those in fr. | ||
if (lang === 'fr') { | ||
merged = { ...fr, ...frMap, ...res }; | ||
} else if (lang === 'en') { | ||
merged = { ...en, ...enMap, ...res }; | ||
} else if (lang === 'es') { | ||
merged = { ...es, ...esMap, ...res }; | ||
} | ||
observer.next(merged); | ||
observer.complete(); | ||
}, | ||
error => { | ||
// failed to retrieve requested language file, use default | ||
observer.complete(); // => Default language is already loaded | ||
} | ||
); | ||
}); | ||
} | ||
} |