Fineract backend settings with environment variables

This commit is contained in:
Jose Alberto Hernandez
2022-07-13 16:40:23 +02:00
committed by Arnold Gálovics
parent 1b72136411
commit 14ceb4f3fd
44 changed files with 815 additions and 291 deletions
+5 -63
View File
@@ -2,16 +2,11 @@
import { Injectable } from '@angular/core';
/** Translation Imports */
import { TranslateService, LangChangeEvent } from '@ngx-translate/core';
import { TranslateService } from '@ngx-translate/core';
/** Custom Services */
import { Logger } from '../logger/logger.service';
/** Other Imports */
import { includes } from 'lodash';
import * as enUS from '../../../translations/en-US.json';
import * as frFR from '../../../translations/fr-FR.json';
/** Initialize Logger */
const log = new Logger('I18nService');
@@ -19,71 +14,18 @@ const log = new Logger('I18nService');
* Pass-through function to mark a string for translation extraction.
* Running `npm translations:extract` will include the given string by using this.
* @param {string} s The string to extract for translation.
* @return {string} The same string.
* @return {string} The translated string.
*/
export function extract(s: string) {
return s;
return I18nService.translate(s);
}
@Injectable()
export class I18nService {
/** Key to store current language of application in local storage. */
private languageStorageKey = 'mifosXLanguage';
defaultLanguage: string;
supportedLanguages: string[];
constructor(private translateService: TranslateService) { }
/**
* Initializes i18n for the application.
* Loads language from local storage if present, or sets default language.
* @param {!string} defaultLanguage The default language to use.
* @param {Array.<String>} supportedLanguages The list of supported languages.
*/
init(defaultLanguage: string, supportedLanguages: string[]) {
this.defaultLanguage = defaultLanguage;
this.supportedLanguages = supportedLanguages;
this.language = '';
this.translateService.onLangChange
.subscribe((event: LangChangeEvent) => { localStorage.setItem(this.languageStorageKey, event.lang); });
public static translate(key: string): string {
return key;
}
/**
* Sets the current language.
* Note: The current language is saved to the local storage.
* If no parameter is specified, the language is loaded from local storage (if present).
* @param {string} language The IETF language code to set.
*/
set language(language: string) {
language = language || localStorage.getItem(this.languageStorageKey) || this.translateService.getBrowserCultureLang();
let isSupportedLanguage = includes(this.supportedLanguages, language);
// If no exact match is found, search without the region
if (language && !isSupportedLanguage) {
language = language.split('-')[0];
language = this.supportedLanguages.find(supportedLanguage => supportedLanguage.startsWith(language)) || '';
isSupportedLanguage = Boolean(language);
}
// Fallback if language is not supported
if (!isSupportedLanguage) {
language = this.defaultLanguage;
}
log.debug(`Language set to ${language}`);
localStorage.setItem(this.languageStorageKey, language);
this.translateService.setDefaultLang(language);
}
/**
* Gets the current language.
* @return {string} The current language code.
*/
get language(): string {
return this.translateService.currentLang;
}
}