Skip to content

Fix various Expressive Code translation issues#1708

Merged
HiDeoo merged 3 commits intowithastro:mainfrom
HiDeoo:hd-fix-ec-translations
Apr 5, 2024
Merged

Fix various Expressive Code translation issues#1708
HiDeoo merged 3 commits intowithastro:mainfrom
HiDeoo:hd-fix-ec-translations

Conversation

@HiDeoo
Copy link
Copy Markdown
Member

@HiDeoo HiDeoo commented Apr 3, 2024

What kind of changes does this PR include?

  • Changes to Starlight code

Description

This PR fixes various issues with the UI strings translation in Expressive Code. I identified two issues:

  • The Expressive Code getBlockLocale() function uses pathToLocale() which can return undefined. This function states the following:

    If the function returns undefined, the default locale provided in the Expressive Code configuration is used.

    Altho, it looks like the default locale was never configured in the Expressive Code configuration.

  • The translation loading mechanism for Expressive Code did not properly handle all possible configuration: monolingual, multilingual, with or without a root locale, etc.

This pull request attempts to fix these 2 issues and also add a few tests to ensure that the expected translations are properly loaded in Expressive Code as we did not have any tests for this part of the codebase.

I would love to get @hippotastic 's feedback on this PR obviously.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2024

🦋 Changeset detected

Latest commit: cb31acc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Apr 5, 2024 1:26pm

Copy link
Copy Markdown
Contributor

@hippotastic hippotastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these fixes! Looks great to me!

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent stuff — thank you @HiDeoo 🎉

Left one comment regarding where the localeToLang() function lives, but this LGTM. Will let you decide whether you want to do anything with that comment before merging.

Comment on lines +38 to +46
/**
* Get the BCP-47 language tag for the given locale.
* @param locale Locale string or `undefined` for the root locale.
*/
export function localeToLang(config: StarlightConfig, locale: string | undefined): string {
const lang = locale ? config.locales?.[locale]?.lang : config.locales?.root?.lang;
const defaultLang = config.defaultLocale?.lang || config.defaultLocale?.locale;
return lang || defaultLang || 'en';
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe live in packages/starlight/integrations/shared/?

Copy link
Copy Markdown
Member Author

@HiDeoo HiDeoo Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, totally forgot about that directory. I'll update that and merge the PR. 👍

@delucis delucis added the 🌟 patch Change that triggers a patch release label Apr 5, 2024
@HiDeoo HiDeoo merged commit a72cb96 into withastro:main Apr 5, 2024
@HiDeoo HiDeoo deleted the hd-fix-ec-translations branch April 5, 2024 13:28
@astrobot-houston astrobot-houston mentioned this pull request Apr 5, 2024
HiDeoo added a commit to HiDeoo/starlight that referenced this pull request Apr 5, 2024
* main: (111 commits)
  Fix various Expressive Code translation issues (withastro#1708)
  Fix nested aside title rendering issue (withastro#1703)
  I18n(pt-PT): Add resources pages (withastro#1678)
  Add SST Ion & Font Awesome to site showcase (withastro#1710)
  [ci] format
  Add SudoVanilla to showcase (withastro#1702)
  i18n(fr): Update `resources-showcase` (withastro#1697)
  [i18nIgnore] docs: update `starlight-links-validator` to version `0.7.1` (withastro#1696)
  [ci] format
  [ci] release (withastro#1688)
  [ci] format
  Update Russian translation (withastro#1616)
  [ci] format
  Adds `starlight` icon to Starlight (withastro#1698)
  Update Icons.ts with Farcaster Purple for SocialIcons (withastro#1622)
  Remove duplicate from showcase example in `contributing.md` (withastro#1692)
  i18n(zh-cn): Update `showcase.mdx` (withastro#1689)
  [ci] format
  i18n(zh-cn): Update configuration.mdx (withastro#1691)
  i18n(ko-KR): update `showcase.mdx` (withastro#1690)
  ...
HiDeoo added a commit to HiDeoo/starlight that referenced this pull request Apr 8, 2024
* main:
  [ci] format
  [ci] release (withastro#1714)
  Fix various Expressive Code translation issues (withastro#1708)
  Fix nested aside title rendering issue (withastro#1703)
  I18n(pt-PT): Add resources pages (withastro#1678)
  Add SST Ion & Font Awesome to site showcase (withastro#1710)
Yoxnear pushed a commit to Yoxnear/starlight-custom that referenced this pull request Jul 23, 2025
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Co-authored-by: Hippo <6137925+hippotastic@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 core Changes to Starlight’s main package 🌟 patch Change that triggers a patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with translating of "Copy to clipboard" text

3 participants