Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nghyd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cassiopée
nghyd
Commits
ff4d2345
Commit
ff4d2345
authored
4 years ago
by
mathias.chouet
Browse files
Options
Downloads
Patches
Plain Diff
Update
#223
: remove unused fallback language loading mechanism
parent
670edfcb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!105
Resolve "Améliorer le système de traduction"
,
!82
Resolve "Ajout de la fonctionnalité "Respect des critères""
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/services/formulaire.service.ts
+0
-8
0 additions, 8 deletions
src/app/services/formulaire.service.ts
src/app/services/internationalisation.service.ts
+4
-28
4 additions, 28 deletions
src/app/services/internationalisation.service.ts
with
4 additions
and
36 deletions
src/app/services/formulaire.service.ts
+
0
−
8
View file @
ff4d2345
...
@@ -130,14 +130,6 @@ export class FormulaireService extends Observable {
...
@@ -130,14 +130,6 @@ export class FormulaireService extends Observable {
&&
langCache
[
this
.
intlService
.
currentLanguage
][
textKey
]
!==
undefined
&&
langCache
[
this
.
intlService
.
currentLanguage
][
textKey
]
!==
undefined
)
{
)
{
return
langCache
[
this
.
intlService
.
currentLanguage
][
textKey
];
return
langCache
[
this
.
intlService
.
currentLanguage
][
textKey
];
}
else
if
(
// try calculator type specific translation, but for default language
langCache
&&
langCache
[
this
.
appSetupService
.
fallbackLanguage
]
&&
langCache
[
this
.
appSetupService
.
fallbackLanguage
][
textKey
]
!==
undefined
)
{
return
langCache
[
this
.
appSetupService
.
fallbackLanguage
][
textKey
];
}
}
}
}
// fallback to global (not calculator type specific) translation system
// fallback to global (not calculator type specific) translation system
...
...
This diff is collapsed.
Click to expand it.
src/app/services/internationalisation.service.ts
+
4
−
28
View file @
ff4d2345
...
@@ -21,9 +21,6 @@ export class I18nService extends Observable implements Observer {
...
@@ -21,9 +21,6 @@ export class I18nService extends Observable implements Observer {
/** localized messages */
/** localized messages */
private
_Messages
:
StringMap
;
private
_Messages
:
StringMap
;
/** localized messages in fallback language (the one in the config file) */
private
_fallbackMessages
:
StringMap
;
/** to avoid loading language files multiple times */
/** to avoid loading language files multiple times */
private
_languageCache
=
{};
private
_languageCache
=
{};
...
@@ -36,10 +33,6 @@ export class I18nService extends Observable implements Observer {
...
@@ -36,10 +33,6 @@ export class I18nService extends Observable implements Observer {
fr
:
"
Français
"
,
fr
:
"
Français
"
,
en
:
"
English
"
en
:
"
English
"
};
};
// load fallback language messages once for all
this
.
httpGetMessages
(
this
.
applicationSetupService
.
fallbackLanguage
).
then
((
res
:
any
)
=>
{
this
.
_fallbackMessages
=
res
;
});
// add language preferences observer
// add language preferences observer
this
.
applicationSetupService
.
addObserver
(
this
);
this
.
applicationSetupService
.
addObserver
(
this
);
}
}
...
@@ -97,20 +90,14 @@ export class I18nService extends Observable implements Observer {
...
@@ -97,20 +90,14 @@ export class I18nService extends Observable implements Observer {
}
}
/**
/**
* Loads the localisation file dedicated to calculator type ct; tries the current
* Loads the localisation file dedicated to calculator type ct; uses cache if available
* language then the fallback language; uses cache if available
*/
*/
public
loadLocalisation
(
calc
:
CalculatorType
):
Promise
<
any
>
{
public
loadLocalisation
(
calc
:
CalculatorType
):
Promise
<
any
>
{
const
lang
=
this
.
currentLanguage
;
const
lang
=
this
.
currentLanguage
;
return
this
.
loadLocalisationForLang
(
calc
,
lang
).
then
((
localisation
)
=>
{
return
this
.
loadLocalisationForLang
(
calc
,
lang
).
then
((
localisation
)
=>
{
return
localisation
as
StringMap
;
return
localisation
as
StringMap
;
}).
catch
((
e
)
=>
{
}).
catch
((
e
)
=>
{
// try default lang (the one in the config file) ?
return
""
;
const
fallbackLang
=
this
.
applicationSetupService
.
fallbackLanguage
;
if
(
lang
!==
fallbackLang
)
{
console
.
error
(
`localisation for
${
CalculatorType
[
calc
]}
not found, trying fallback language:
${
fallbackLang
}
`
);
return
this
.
loadLocalisationForLang
(
calc
,
fallbackLang
);
}
});
});
}
}
...
@@ -120,12 +107,8 @@ export class I18nService extends Observable implements Observer {
...
@@ -120,12 +107,8 @@ export class I18nService extends Observable implements Observer {
*/
*/
private
loadLocalisationForLang
(
calc
:
CalculatorType
,
lang
:
string
):
Promise
<
any
>
{
private
loadLocalisationForLang
(
calc
:
CalculatorType
,
lang
:
string
):
Promise
<
any
>
{
const
ct
=
String
(
calc
);
const
ct
=
String
(
calc
);
// already in cache ?
// if not already in cache
if
(
Object
.
keys
(
this
.
_languageCache
).
includes
(
ct
)
&&
Object
.
keys
(
this
.
_languageCache
[
calc
]).
includes
(
lang
))
{
if
(
!
Object
.
keys
(
this
.
_languageCache
).
includes
(
ct
)
||
!
Object
.
keys
(
this
.
_languageCache
[
calc
]).
includes
(
lang
))
{
return
new
Promise
((
resolve
)
=>
{
resolve
(
this
.
_languageCache
[
ct
][
lang
]);
});
}
else
{
const
f
:
string
=
FormulaireService
.
getConfigPathPrefix
(
calc
)
+
lang
+
"
.json
"
;
const
f
:
string
=
FormulaireService
.
getConfigPathPrefix
(
calc
)
+
lang
+
"
.json
"
;
return
this
.
httpService
.
httpGetRequestPromise
(
f
).
then
((
localisation
)
=>
{
return
this
.
httpService
.
httpGetRequestPromise
(
f
).
then
((
localisation
)
=>
{
this
.
_languageCache
[
ct
]
=
this
.
_languageCache
[
ct
]
||
{};
this
.
_languageCache
[
ct
]
=
this
.
_languageCache
[
ct
]
||
{};
...
@@ -165,7 +148,6 @@ export class I18nService extends Observable implements Observer {
...
@@ -165,7 +148,6 @@ export class I18nService extends Observable implements Observer {
* In production mode, looks in different messages collections :
* In production mode, looks in different messages collections :
* 1. ${msg} if provided
* 1. ${msg} if provided
* 2. messages for current language
* 2. messages for current language
* 3. messages for fallback language
*
*
* In dev mode, looks only in 1. if provided, else only in 2. which makes missing
* In dev mode, looks only in 1. if provided, else only in 2. which makes missing
* translations easier to detect
* translations easier to detect
...
@@ -183,12 +165,6 @@ export class I18nService extends Observable implements Observer {
...
@@ -183,12 +165,6 @@ export class I18nService extends Observable implements Observer {
if
(
this
.
_Messages
!==
undefined
&&
this
.
_Messages
[
"
INFO_LIB_
"
+
textKey
.
toUpperCase
()]
!==
undefined
)
{
if
(
this
.
_Messages
!==
undefined
&&
this
.
_Messages
[
"
INFO_LIB_
"
+
textKey
.
toUpperCase
()]
!==
undefined
)
{
return
decodeHtml
(
this
.
_Messages
[
"
INFO_LIB_
"
+
textKey
.
toUpperCase
()]);
return
decodeHtml
(
this
.
_Messages
[
"
INFO_LIB_
"
+
textKey
.
toUpperCase
()]);
}
}
if
(
!
isDevMode
())
{
// try fallback language before giving up
if
(
this
.
_fallbackMessages
[
textKey
]
!==
undefined
)
{
return
decodeHtml
(
this
.
_fallbackMessages
[
textKey
]);
}
}
return
`*** message not found:
${
textKey
}
***`
;
return
`*** message not found:
${
textKey
}
***`
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment