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

Implement UI string translation using data collections #78

Merged
merged 23 commits into from
May 23, 2023

Conversation

delucis
Copy link
Member

@delucis delucis commented May 20, 2023

What kind of changes does this PR include?

  • Changes to Starlight code

Description

  • Adds support for translating elements of Starlight’s UI.

Users can provide translations in JSON files in src/content/i18n/ which is a data collection, for example a src/content/i18n/de.json:

{
  "search.label": "Suchen",
  "search.shortcutLabel": "(Drücke / zum Suchen)"
}

In Starlight templates, we look up strings for the current locale from this data collection, falling back to the user-configured default locale, or to Starlight’s English defaults. This PR also adds built-in support for Spanish & German. The aim would be that for major languages we provide language support out of the box and users only need manual config to override labels or if they support less common languages.

Not included

Mapping languages to dictionaries is a bit basic so far, e.g. de-CH wouldn’t find de translations. Leaving that to a follow-up PR, e.g with a library like https://github.com/wooorm/bcp-47-match

@changeset-bot
Copy link

changeset-bot bot commented May 20, 2023

🦋 Changeset detected

Latest commit: 898aa56

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

@netlify
Copy link

netlify bot commented May 20, 2023

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit 898aa56
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/646cbbc8a3fa6e0008596248
😎 Deploy Preview https://deploy-preview-78--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@astrobot-houston
Copy link
Collaborator

astrobot-houston commented May 20, 2023

size-limit report 📦

Path Size
/index.html 10.7 KB (+0.08% 🔺)
/_astro/*.js 15.96 KB (0%)
/_astro/*.css 8.87 KB (0%)

@dreyfus92
Copy link
Member

This looks great @delucis but I'm wondering if you need to change something else in the astro.config.mjs file to be able to see the updated UI in german?

@delucis
Copy link
Member Author

delucis commented May 20, 2023

Ah, this doesn't yet fix #70! This is only for the static parts of the UI like the search bar, table of contents, etc. That looks like it's working ok in the preview, I think?

Will work to fix #70 as well soon!

@dreyfus92
Copy link
Member

It works in the preview 😃

@delucis delucis merged commit d3ee6fc into main May 23, 2023
@delucis delucis deleted the dx-22/i18n-data-collections branch May 23, 2023 13:18
@astrobot-houston astrobot-houston mentioned this pull request May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants