Skip to content
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

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

RasmusKjeldgaard
Copy link
Collaborator

@RasmusKjeldgaard RasmusKjeldgaard commented Nov 21, 2024

Draft notes

  • Setting translation from locale only happens on initialization, but added a method to update it. Is this sufficient or do we need to be reactive?
    • I guess for most of our consumers language change will not be dynamic, but instead reload another build of the application. So maybe sufficient for now?
  • Thouht about providing a way to overwrite or add new translations but ended up de-scoping it

Which issue does this PR close?

This PR closes #3694 closes #942

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

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

  • Make sure you have implemented tests following the guidelines in: "The good: Test".
  • Make sure you have updated the cookbook with examples and showcases (for bug fixes, enhancements & new components).

Review

  • Determine if your changes are a fix, feature or breaking-change, and add the matching label to your PR. If it is tooling, dependency updates or similar, add ignore-for-release.
  • Do a self-review.
  • Request that the changes are code-reviewed
  • Request that the changes are UX reviewed (only necessary if your PR introduces visual changes)

When the pull request has been approved it will be merged to develop by Team Kirby.

@RasmusKjeldgaard RasmusKjeldgaard changed the title Add translation service and initial translations Accessibility: Add internal component translations Nov 21, 2024
@RasmusKjeldgaard RasmusKjeldgaard changed the title Accessibility: Add internal component translations Accessibility: add internal component translations Nov 21, 2024
@github-actions github-actions bot temporarily deployed to pr-3694-translate-internal-labels November 21, 2024 10:33 Inactive
Copy link
Collaborator

@Fuzzy3 Fuzzy3 left a 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];
Copy link
Collaborator

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 🤔

Suggested change
const baseLocaleId = localeId.split('-')[0];
const [baseLocaleId] = localeId.split('-');

Copy link
Collaborator Author

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"`);
Copy link
Collaborator

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 😆

Copy link
Collaborator Author

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 😘

Copy link
Collaborator

@jakobe jakobe left a 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];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants