Skip to content

[BpkStylesheets] Add locale-specific font-family overrides for non-Latin languages#4343

Merged
Xiaoguang Liu (xiaogliu) merged 7 commits intomainfrom
xiaogliu/font-locale-override
Apr 15, 2026
Merged

[BpkStylesheets] Add locale-specific font-family overrides for non-Latin languages#4343
Xiaoguang Liu (xiaogliu) merged 7 commits intomainfrom
xiaogliu/font-locale-override

Conversation

@xiaogliu
Copy link
Copy Markdown
Contributor

@xiaogliu Xiaoguang Liu (xiaogliu) commented Apr 1, 2026

Description

Adds CSS [lang] attribute overrides for non-Latin locales so that Noto fonts are only downloaded when the page locale matches (e.g. lang="ja-JP", lang="ar").

Design doc

Fallback Fonts — Backpack Design System

Problem

backpack-foundations PR #485 added all Noto Sans fonts to the global font-family stack. This caused every page (including English) to download large CJK/non-Latin fonts whenever any non-Latin character appeared (e.g. language switcher), leading to:

  • CloudFront data transfer costs jumping from ~$250/day to ~$650/day
  • Font transfer volume increasing from ~4.2 TB/day to ~24 TB/day

Solution

  • Foundations repo: Revert the global font-family change (separate PR)
  • This PR: Add per-locale font-family CSS variable overrides using [lang] / :lang() selectors, so non-Latin Noto fonts are only loaded on pages with the matching locale

New locale overrides added

Script Locale Primary Font File
Japanese ja-JP Noto Sans JP / Noto Serif JP font.scss, larken.scss
Traditional Chinese zh-TW, zh-HK Noto Sans TC / Noto Serif TC font.scss, larken.scss
Simplified Chinese zh-CN Noto Sans SC / Noto Serif SC font.scss, larken.scss
Korean ko-KR Noto Sans KR / Noto Serif KR font.scss, larken.scss
Thai th-TH Noto Sans Thai / Noto Serif Thai font.scss, larken.scss
Hindi (Devanagari) hi-IN Noto Sans Devanagari / Noto Serif Devanagari font.scss, larken.scss
Arabic ar Noto Sans Arabic font.scss, larken.scss
Hebrew he Noto Sans Hebrew / Noto Serif Hebrew font.scss, larken.scss
Greek el-GR Noto Sans / Noto Serif font.scss, larken.scss
Cyrillic ru-RU, uk-UA, bg-BG Noto Sans / Noto Serif font.scss, larken.scss
Vietnamese vi-VN Noto Sans / Noto Serif font.scss, larken.scss

Also updated Storybook font examples to include lang attributes for all non-Latin language samples.

Screenshots

lang = ja-JP

image

lang = ko-KR

image

Checklist

  • PR title includes component name
  • Storybook examples updated with lang attributes for all non-Latin samples
  • All locales from fallback fonts design doc are covered
  • No new components added (no README needed)
  • No breaking changes
  • Verified font loading behavior via Storybook Network tab

Copilot AI review requested due to automatic review settings April 1, 2026 10:17
@xiaogliu Xiaoguang Liu (xiaogliu) added the patch Patch production bug label Apr 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds locale-aware font-family stack overrides to bpk-stylesheets so script-specific Noto fonts are preferred only when the relevant lang is present, reducing unnecessary downloads triggered by non-Latin glyphs on otherwise Latin pages.

Changes:

  • Added [lang] / :lang() overrides for additional non-Latin locales to set --bpk-base-font-stack (Skyscanner Relative) and --bpk-larken-font-stack (Larken).
  • Included new locale coverage for zh-HK, zh-CN, ko-KR, th-TH, hi-IN, ar, and he (plus existing ja-JP, zh-TW).
  • Updated the font examples to apply lang attributes to non-Latin samples and added a zh-HK sample.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/bpk-stylesheets/font.scss Adds locale-specific overrides for the base font stack via CSS variables and lang selectors.
packages/bpk-stylesheets/larken.scss Adds matching locale-specific overrides for the Larken/editorial font stack via CSS variables and lang selectors.
examples/bpk-stylesheets-fonts/examples.tsx Updates Storybook/example rendering to include lang attributes for non-Latin samples and adds a zh-HK sample.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/bpk-stylesheets/src/BpkStylesheetsFonts.stories.tsx
Comment thread packages/bpk-stylesheets/font.scss Outdated
Comment thread packages/bpk-stylesheets/font.scss
Comment thread packages/bpk-stylesheets/larken.scss
@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4343 to see this build running in a browser.

1 similar comment
@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4343 to see this build running in a browser.

@xiaogliu
Copy link
Copy Markdown
Contributor Author

Xiaoguang Liu (xiaogliu) commented Apr 2, 2026

Non-Latin font handling in backpack-foundations

The global font-family revert is handled in a separate PR in the foundations repo:

This reverts backpack-foundations #485 which added all Noto Sans/Serif fonts to the global font-family stack, causing non-Latin fonts to be downloaded on every page (even English pages) whenever any non-Latin character appeared (e.g. language switcher).

Two-part fix (CLOV-1508):

  1. Foundations repo (PR Send props to "BpkAccordion" when using "withAccordionItemState" #490): Revert the global font-family to its previous state — Latin-script pages will use system default fonts for non-Latin characters
  2. This PR (backpack [BpkStylesheets] Add locale-specific font-family overrides for non-Latin languages #4343): Add per-locale [lang] CSS overrides so non-Latin Noto fonts are only loaded when the page locale matches (e.g. lang="ja-JP" loads Noto Sans JP)

This approach ensures non-Latin fonts are only downloaded when actually needed, bringing CloudFront costs back down from ~$650/day to ~$250/day.

'Helvetica Neue', sans-serif;
}

[lang='el-GR'],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems all font setting of 'el-GR' ru-RU vi-VN are same, are they expected? if so, could we merged them?

'Noto Serif Devanagari', 'Noto Serif Thai', sans-serif;
}

[lang='el-GR'],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4343 to see this build running in a browser.

Vincent Liu and others added 6 commits April 14, 2026 18:23
…tin languages

Add CSS lang-attribute overrides so non-Latin Noto fonts are only loaded
when the page locale matches (e.g. lang="ja-JP", lang="ar"), preventing
unnecessary font downloads on Latin-language pages that previously caused
a ~2.5x increase in CloudFront data transfer costs.

New locale overrides added for: zh-HK, zh-CN, ko-KR, th-TH, hi-IN, ar, he.
Updated Storybook examples to include lang attributes for all non-Latin
language samples to enable proper visual verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Type LANGUAGE_SAMPLES and remove `as any` casts for type-safe lang access
- Reword font.scss comment to accurately describe selector behavior
- Merge duplicate zh-TW/zh-HK selectors in both font.scss and larken.scss

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add font-family overrides for el-GR (Greek), ru-RU/uk-UA/bg-BG (Cyrillic),
and vi-VN (Vietnamese) to match the fallback fonts documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These locales share the same Noto Sans / Noto Serif font stack,
so combine them into a single rule in both font.scss and larken.scss.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xiaogliu Xiaoguang Liu (xiaogliu) force-pushed the xiaogliu/font-locale-override branch from 799fd55 to 06d30c8 Compare April 14, 2026 10:25
@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4343 to see this build running in a browser.

Include the latest foundations release which reverts the global
font-family change, so consumers get both fixes in a single upgrade.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xiaogliu Xiaoguang Liu (xiaogliu) force-pushed the xiaogliu/font-locale-override branch from 06d30c8 to 7a58fad Compare April 15, 2026 02:33
@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4343 to see this build running in a browser.

@xiaogliu Xiaoguang Liu (xiaogliu) merged commit 8d3bbe5 into main Apr 15, 2026
15 checks passed
@xiaogliu Xiaoguang Liu (xiaogliu) deleted the xiaogliu/font-locale-override branch April 15, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants