-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: first draft of i18n in authorize page #172
Open
matteo-cristino
wants to merge
1
commit into
main
Choose a base branch
from
feat/i18n
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -13,13 +13,7 @@ | |
src="https://cdn.jsdelivr.net/npm/@didroom/components/dist/didroom-components/didroom-components.esm.js"></script> | ||
<link rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/@didroom/components/dist/didroom-components/didroom-components.css" /> | ||
<script> | ||
tailwind.config = { | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
], | ||
} | ||
</script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/21.6.6/i18next.min.js"></script> | ||
</head> | ||
|
||
<body class="font-sans antialised flex flex-col h-full min-h-screen bg-primary p-8"> | ||
|
@@ -35,7 +29,7 @@ | |
<form id="params"> | ||
<div id="form"></div> | ||
<div class="flex w-full"> | ||
<d-button color="accent" id="execute" expand="true" class="w-full mt-4">AUTHENTICATE</d-button> | ||
<d-button color="accent" id="execute" expand="true" class="w-full mt-4" data-i18n="authenticate">AUTHENTICATE</d-button> | ||
<div class="ml-4 h-8 w-10 animate-bounce htmx-indicator hidden"> | ||
<div class="mx-auto h-8 w-8 animate-pulse rounded-full bg-gray-300"></div> | ||
<span class="absolute flex h-6 w-6 animate-spin"> | ||
|
@@ -49,6 +43,36 @@ | |
</div> | ||
</main> | ||
<script> | ||
// i18n | ||
const userLanguage = navigator.language || navigator.userLanguage; | ||
const supportedLanguages = ['en-US', 'it-IT']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this list should be taken from the .well-known |
||
const defaultLanguage = supportedLanguages.includes(userLanguage) ? userLanguage : 'en-US'; | ||
i18next.init({ | ||
lng: defaultLanguage, | ||
debug: false, | ||
resources: { | ||
en: { | ||
translation: { | ||
"authenticate": "AUTHENTICATE", | ||
} | ||
}, | ||
it: { | ||
translation: { | ||
"authenticate": "AUTENTICA", | ||
} | ||
} | ||
} | ||
}, function (err, t) { | ||
updateContent(); | ||
}); | ||
|
||
function updateContent() { | ||
document.querySelectorAll("[data-i18n]").forEach(function (element) { | ||
const key = element.getAttribute("data-i18n"); | ||
element.textContent = i18next.t(key); | ||
}); | ||
} | ||
|
||
// get url | ||
const paramsIdx = document.URL.indexOf('?'); | ||
const baseUrl = document.URL.substring(0, paramsIdx - "authorize".length - 1); | ||
|
@@ -99,9 +123,11 @@ | |
fetch(`${issuerUrl}/.well-known/openid-credential-issuer`) | ||
.then((response) => response.json()) | ||
.then((wk) => { | ||
const credentialInfo = wk.credential_configurations_supported.filter( | ||
const credentialInfoDisplay = wk.credential_configurations_supported.find( | ||
(c) => c.credential_definition.type[0] === type | ||
)[0].display[0]; | ||
).display | ||
const credentialInfo = credentialInfoDisplay.find((d) => d.locale === userLanguage) || | ||
credentialInfoDisplay.find((d) => d.locale === 'en-US'); | ||
$("#avatar").attr("name", credentialInfo?.name) | ||
$("#avatar").attr("alt", credentialInfo?.logo.alt_text) | ||
$("#avatar").attr("src", credentialInfo?.logo.url) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awww this is super needed! for .md descriptions especially! plz take it back!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems broken since require is not defined in the browser and after a bit of research it look like that, from the url we use to include tailwind, thi plugin is already included... but I just had a quick look, will have a better look at it