question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for localized theme overrides

See original GitHub issue

Is your feature request related to a problem? Please describe. When creating an internationalized site, sometimes you would want different stylings for different languages. For example, languages such as Japanese or Chinese might require a different font family and font size, and some widths need to be adjusted to account for different text lengths across languages.

Currently, the only way to really do this is to query on individual languages across styles.

const { locale } = useIntl() // get locale from some provider
<Box
  sx={{
    fontFamily: locale === "ja" ? "Mincho" : "Helvetica"
  }} />

This is cumbersome, especially when multiple languages are involved across multiple components and styles.

Describe the solution you’d like Ideally, theme-ui would be able to define overrides on themes based on locale:

theme = {
  fonts: {
    body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif',
    heading: 'Georgia, serif',
    monospace: 'Menlo, monospace',
  },
  fontSizes: [
    12, 14, 16, 20, 24, 32, 48, 64
  ],
  ja: { // Override fonts and font sizes for Japanese
    fonts: {
      body: 'Mincho, system-ui'
    },
    fontSizes: [
      10, 12, 14, 18, 22, 30, 40, 60
    ]
  }
}

The locale can be set using a useLocale() hook that works much like the useColorMode() hook:

const [, setLocale] = useLocale()
setLocale(locale) // set to locale

Describe alternatives you’ve considered N/A

Additional context Related: #689

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
tesseraliscommented, Feb 18, 2020

I feel like the “partial themes” option is better and would be easier to work with from a developer perspective. You’re usually looking at a page in a single locale and thinking “what are the style edits I need to do to make this work” rather than, say, scrolling through all the languages and checking the fonts for each one.

As for interfacing with other i18n related tools – most of them provide a locale or lang value through a hook, HOC, or render prop and as long as theme-ui can interface with that, we should be good.

Some popular i18n tools for React are:

2reactions
hasparuscommented, Feb 16, 2021

hey @rojobuffalo, I update the link in Lachlan’s message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theme override support for custom components - Stack Overflow
The overridesResolver property is meant to resolve this object: const theme = { components: { [PREFIX]: { styleOverrides: /* this object, ...
Read more >
How to create theme localization - Zemez Support
Go to Extensions -> Languages, and open the Overrides tab. In the language Filter select your language and click New button.
Read more >
Local configuration overrides — Powerline beta documentation
Vim overrides¶. Vim configuration can be overridden using the following options: g:powerline_config_overrides: Dictionary, recursively merged with contents ...
Read more >
Global Styling with Material-UI Theme Overrides and Props
Learn how to use global CSS overrides and default props in a theme to customize all instances of a Material-UI component in a...
Read more >
How do I override a parent theme's language files with a child ...
If you want to change more than just the stylesheet, your child theme can override any file in the parent theme: simply include...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found