-
Notifications
You must be signed in to change notification settings - Fork 23
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
Accessibility: add internal component translations #3717
base: develop
Are you sure you want to change the base?
Accessibility: add internal component translations #3717
Conversation
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.
Really good reflections in your draft notes ! I don't think there would be a more clean way of handling translations than this, for such a small set of translations. let's not bring out the big hammer and do reactiveness before it is actually an identified need. good PR, great scope ! ❤️
} | ||
|
||
setCurrentTranslation(localeId: string): string { | ||
const baseLocaleId = localeId.split('-')[0]; |
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.
Don't know if destructuring is more readable 🤔
const baseLocaleId = localeId.split('-')[0]; | |
const [baseLocaleId] = localeId.split('-'); |
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.
In this case I think it reads a bit better that you can go "split string and take the first substring" rather than having to understand the destructuring part 🤔 So I'll leave it as is if ok.
const translation = this.translations[baseLocaleId]; | ||
|
||
if (!translation) { | ||
console.warn(`Translation not found for locale "${this.localeId}", falling back to "en"`); |
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.
Well... I guess there could be a scenario where the currentTranslation was changed to danish earlier - and then I guess we are not falling back to english. I don't think that is a likely scenario though 😆
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.
Good point, I'll make it so it takes the fallback value from the activeTranslation instead 😘
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.
Great work, Raz 👌🏻
I like the scoping you've done, we can always later add support for changes to the locale 👍🏻
Maybe we can shorten the syntax a bit? I.e.
Consuming component:
constructor(
...,
public translations: TranslationService
) {
Template binding:
[attr.aria-label]="translations.get('previousMonth')"
and then in TranslationService:
get(key: keyof Translation): string {
return this.currentTranslation[key];
}
Draft notes
Which issue does this PR close?
This PR closes #3694 closes #942
What is the new behavior?
Does this PR introduce a breaking change?
Are there any additional context?
Checklist:
The following tasks should be carried out in sequence in order to follow the process of contributing correctly.
Reminders
Review
When the pull request has been approved it will be merged to
develop
by Team Kirby.