Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
68ee78a5
Commit
68ee78a5
authored
2 years ago
by
Kocher, Manuel
Browse files
Options
Downloads
Patches
Plain Diff
add missing file error handling to translation-overrides
parent
8eb4a610
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/common/i18next.js
+22
-11
22 additions, 11 deletions
packages/common/i18next.js
with
22 additions
and
11 deletions
packages/common/i18next.js
+
22
−
11
View file @
68ee78a5
...
@@ -9,8 +9,14 @@ async function fetchOverridesByLanguage(overrides, lng) {
...
@@ -9,8 +9,14 @@ async function fetchOverridesByLanguage(overrides, lng) {
fetch
(
overrides
+
lng
+
'
/translation.json
'
,
{
fetch
(
overrides
+
lng
+
'
/translation.json
'
,
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
});
});
let
json
=
await
result
.
json
();
return
json
;
// throw error if response is not json
try
{
let
json
=
await
result
.
json
();
return
json
;
}
catch
(
e
)
{
throw
new
Error
(
"
Could not parse response as json:
"
+
e
);
}
}
}
// handles translation cache promises
// handles translation cache promises
...
@@ -165,21 +171,26 @@ export async function setOverridesByGlobalCache(i18n, element) {
...
@@ -165,21 +171,26 @@ export async function setOverridesByGlobalCache(i18n, element) {
// to the original one. This way we an change the overrides at runtime
// to the original one. This way we an change the overrides at runtime
// and can even remove them.
// and can even remove them.
// The scoped mixin saves the real tag name under data-tag-name
// The scoped mixin saves the real tag name under data-tag-name
let
tagName
=
((
element
.
dataset
&&
element
.
dataset
.
tagName
)
||
element
.
tagName
).
toLowerCase
();
let
tagName
=
((
element
.
dataset
&&
element
.
dataset
.
tagName
)
||
element
.
tagName
).
toLowerCase
();
let
namespace
=
i18n
.
options
.
fallbackNS
;
let
namespace
=
i18n
.
options
.
fallbackNS
;
let
overrideNamespace
=
getOverrideNamespace
(
namespace
);
let
overrideNamespace
=
getOverrideNamespace
(
namespace
);
let
hasOverrides
=
false
;
let
hasOverrides
=
false
;
for
(
let
lng
of
i18n
.
languages
)
{
for
(
let
lng
of
i18n
.
languages
)
{
cacheOverrides
(
element
.
langDir
,
lng
);
// check if cacheOverrides throws error
translationCache
[
lng
]
=
await
translationCache
[
lng
];
try
{
i18n
.
removeResourceBundle
(
lng
,
overrideNamespace
);
cacheOverrides
(
element
.
langDir
,
lng
);
if
(
translationCache
[
lng
]
===
undefined
||
translationCache
[
lng
][
tagName
]
===
undefined
)
continue
;
translationCache
[
lng
]
=
await
translationCache
[
lng
];
let
resources
=
translationCache
[
lng
][
tagName
];
i18n
.
removeResourceBundle
(
lng
,
overrideNamespace
);
hasOverrides
=
true
;
if
(
translationCache
[
lng
]
===
undefined
||
translationCache
[
lng
][
tagName
]
===
undefined
)
continue
;
i18n
.
addResourceBundle
(
lng
,
overrideNamespace
,
resources
);
let
resources
=
translationCache
[
lng
][
tagName
];
hasOverrides
=
true
;
i18n
.
addResourceBundle
(
lng
,
overrideNamespace
,
resources
);
}
catch
(
e
)
{
// leave loop and use default translations if error is thrown
hasOverrides
=
false
;
break
;
}
}
}
i18n
.
setDefaultNamespace
(
hasOverrides
?
overrideNamespace
:
namespace
);
i18n
.
setDefaultNamespace
(
hasOverrides
?
overrideNamespace
:
namespace
);
element
.
requestUpdate
();
element
.
requestUpdate
();
...
...
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