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
GitLab 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
a494d5e0
Commit
a494d5e0
authored
2 years ago
by
Kocher, Manuel
Browse files
Options
Downloads
Patches
Plain Diff
Add innerText to dbp-translation (cypress support), rework showcase example
parent
40c678c2
No related branches found
No related tags found
No related merge requests found
Pipeline
#221168
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/common/dbp-common-demo.js
+6
-6
6 additions, 6 deletions
packages/common/dbp-common-demo.js
packages/common/src/translation.js
+28
-17
28 additions, 17 deletions
packages/common/src/translation.js
with
34 additions
and
23 deletions
packages/common/dbp-common-demo.js
+
6
−
6
View file @
a494d5e0
...
@@ -301,6 +301,7 @@ html {
...
@@ -301,6 +301,7 @@ html {
<div class="control" id="dbp-translated-demo">
<div class="control" id="dbp-translated-demo">
<dbp-translated subscribe="lang">
<dbp-translated subscribe="lang">
<div slot="de">
<div slot="de">
<!---->
Dieser Text ist Deutsch und wird Englisch werden wenn man die
Dieser Text ist Deutsch und wird Englisch werden wenn man die
Sprache auf Englisch stellt.
Sprache auf Englisch stellt.
</div>
</div>
...
@@ -314,13 +315,12 @@ html {
...
@@ -314,13 +315,12 @@ html {
<div class="content">
<div class="content">
<h2>Translation Demo</h2>
<h2>Translation Demo</h2>
<div class="control" id="dbp-translation-demo">
<div class="control" id="dbp-translation-demo">
<dbp-translation subscribe="lang, lang-dir" key="link" var='{"linkDE": "https://www.tugraz.at/home/", "linkEN": "https://www.tugraz.at/en/home/"}' unsafe></dbp-translation><br/>
<dbp-translation id="dbp-translation-link" subscribe="lang, lang-dir" key="link" var='{"linkDE": "https://www.tugraz.at/home/", "linkEN": "https://www.tugraz.at/en/home/"}' unsafe></dbp-translation><br/>
<dbp-translation subscribe="lang, lang-dir" key="theme-switcher-demo"></dbp-translation>
<dbp-translation id="dbp-translation-showcase" subscribe="lang, lang-dir" key="toolkit-showcase"></dbp-translation><br/>
<dbp-translation id="dbp-translation-theme-switcher" subscribe="lang, lang-dir" key="theme-switcher-demo"></dbp-translation><br/>
<dbp-theme-switcher subscribe="lang, lang-dir"
<dbp-theme-switcher subscribe="lang, lang-dir"
themes='[{"class": "light-theme", "icon": "sun", "name": "
${
this
.
_i18n
.
t
(
'
dbp.themes.light-mode
'
)}
"}, {"class": "dark-theme", "icon": "night", "name": "
${
this
.
_i18n
.
t
(
'
dbp.themes.dark-mode
'
)}
"}]'></dbp-theme-switcher>
themes='[{"class": "light-theme", "icon": "sun", "name": "Light Mode"}, {"class": "dark-theme", "icon": "night", "name": "Dark Mode"}]'></dbp-theme-switcher>
<dbp-translation key="toolkit-showcase" subscribe="lang, lang-dir"></dbp-translation>
<dbp-translation key="abc" subscribe="lang, lang-dir"></dbp-translation> <!-- shouldnt be displayed -->
<dbp-translation key="toolkit-showcase-link" var='{"link1": "https://www.i18next.com/translation-function/interpolation"}' subscribe="lang, lang-dir" unsafe></dbp-translation>
<dbp-translation key="abc" subscribe="lang, lang-dir"></dbp-translation>
</div>
</div>
</div>
</div>
</section>
</section>
...
...
This diff is collapsed.
Click to expand it.
packages/common/src/translation.js
+
28
−
17
View file @
a494d5e0
...
@@ -15,6 +15,7 @@ export class Translation extends DBPLitElement {
...
@@ -15,6 +15,7 @@ export class Translation extends DBPLitElement {
// dir and i18next instance of translation overrides
// dir and i18next instance of translation overrides
this
.
_i18n
=
createInstance
();
this
.
_i18n
=
createInstance
();
this
.
langDir
=
''
;
this
.
langDir
=
''
;
this
.
innerText
=
''
;
}
}
...
@@ -72,17 +73,25 @@ export class Translation extends DBPLitElement {
...
@@ -72,17 +73,25 @@ export class Translation extends DBPLitElement {
this
.
_i18n
.
options
.
fallbackNS
:
this
.
_i18n
.
options
.
fallbackNS
:
getOverrideNamespace
(
this
.
_i18n
.
options
.
fallbackNS
);
getOverrideNamespace
(
this
.
_i18n
.
options
.
fallbackNS
);
let
translation
=
""
;
// request to i18n translation
// request to i18n translation
let
translation
=
(()
=>
{
if
(
this
.
interpolation
&&
this
.
unsafe
)
{
if
(
this
.
interpolation
&&
this
.
unsafe
)
this
.
innerText
=
this
.
_i18n
.
t
(
this
.
key
,
this
.
interpolation
);
return
unsafeHTML
(
this
.
_i18n
.
t
(
this
.
key
,
this
.
interpolation
));
translation
=
unsafeHTML
(
this
.
_i18n
.
t
(
this
.
key
,
this
.
interpolation
));
else
if
(
this
.
interpolation
)
}
return
this
.
_i18n
.
t
(
this
.
key
,
this
.
interpolation
);
else
if
(
this
.
interpolation
)
{
else
if
(
this
.
unsafe
)
this
.
innerText
=
this
.
_i18n
.
t
(
this
.
key
,
this
.
interpolation
);
return
unsafeHTML
(
this
.
_i18n
.
t
(
this
.
key
));
translation
=
this
.
_i18n
.
t
(
this
.
key
,
this
.
interpolation
);
else
}
return
this
.
_i18n
.
t
(
this
.
key
);
else
if
(
this
.
unsafe
)
{
})();
this
.
innerText
=
this
.
_i18n
.
t
(
this
.
key
);
translation
=
unsafeHTML
(
this
.
_i18n
.
t
(
this
.
key
));
}
else
{
this
.
innerText
=
this
.
_i18n
.
t
(
this
.
key
);
translation
=
this
.
_i18n
.
t
(
this
.
key
);
}
...
@@ -94,14 +103,16 @@ export class Translation extends DBPLitElement {
...
@@ -94,14 +103,16 @@ export class Translation extends DBPLitElement {
||
window
.
location
.
hash
.
includes
(
'
debug
'
))
{
||
window
.
location
.
hash
.
includes
(
'
debug
'
))
{
keyComment
=
unsafeHTML
(
"
<!-- key:
"
+
this
.
key
+
"
-->
"
);
keyComment
=
unsafeHTML
(
"
<!-- key:
"
+
this
.
key
+
"
-->
"
);
}
else
if
(
this
.
_i18n
.
hasResourceBundle
(
this
.
lang
,
overrideNamespace
)){
}
else
if
(
this
.
_i18n
.
hasResourceBundle
(
this
.
lang
,
overrideNamespace
)){
keyComment
=
unsafeHTML
(
"
<!-- key '
"
+
this
.
key
+
"
' not found! -->
"
)
;
this
.
innerText
=
""
;
translation
=
""
;
translation
=
""
;
keyComment
=
unsafeHTML
(
"
<!-- key '
"
+
this
.
key
+
"
' not found! -->
"
);
console
.
error
(
"
Key '
"
+
this
.
key
+
"
' not found!
"
);
console
.
error
(
"
Key '
"
+
this
.
key
+
"
' not found!
"
);
}
else
{
}
else
{
keyComment
=
unsafeHTML
(
"
<!-- key '
"
+
this
.
key
+
"
' and namespace '
"
+
overrideNamespace
+
"
' not found! -->
"
)
;
this
.
innerText
=
""
;
translation
=
""
;
translation
=
""
;
keyComment
=
unsafeHTML
(
"
<!-- key '
"
+
this
.
key
+
"
' and namespace '
"
+
overrideNamespace
+
"
' not found! -->
"
);
console
.
error
(
"
Key '
"
+
this
.
key
+
"
' and namespace '
"
+
overrideNamespace
+
"
' not found!
"
);
}
}
// load translation text
// load translation text
return
html
`
return
html
`
${
keyComment
}
${
keyComment
}
...
...
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