Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

[NOJIRA]add locale-aware line-break rules for non-Latin scripts - #4732

Merged
GC Zhu (gc-skyscanner) merged 7 commits into
mainfrom
fix/i18n-locale-line-break-rules
Jul 27, 2026
Merged

GC Zhu (gc-skyscanner) merged 7 commits into
mainfrom
fix/i18n-locale-line-break-rules

Conversation

@IrinaWei

@IrinaWei IrinaWei commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Add :lang() CSS rules to font.scss so kinsoku shori (JIS X 4051) and equivalent rules are enforced globally via the existing attribute — no per-component changes required.

Key decisions:

  • line-break: strict for CJK/Korean fixes punctuation/particles appearing at line-start (を、に、の etc. must not begin a line)
  • Japanese base rule wraps per-character under kinsoku (no word-break: keep-all) so it never overflows in browsers without auto-phrase; Chromium is upgraded to phrase-level breaks via @supports (word-break: auto-phrase)
  • overflow-wrap: break-word for CJK as last-resort fallback; preserves Latin brand names and URLs on mixed-script pages unlike word-break: break-all
  • word-break: keep-all for Korean preserves syllable-block boundaries; overflow-wrap: break-word fallback handles 360–390px narrow viewports
  • bpk-breakpoint-query-small-tablet (48rem) loosens line-break to loose for CJK/Korean to avoid uneven rag on narrow screens
  • Thai uses break-all + overflow-wrap: anywhere — no word spaces, ICU dictionary failure leaves zero break points otherwise
  • Arabic/Hebrew: overflow-wrap only; direction left to existing html[dir] RTL system
  • Russian/Ukrainian: hyphens: auto degrades silently in Chrome

Japanese line breaking across browsers

Japanese has no word spaces, so there is no single CSS declaration that gives phrase-aware (文節) breaks everywhere. We handle it in layers:

  • Chromium (Chrome/Edge) — word-break: auto-phrase breaks at natural phrase boundaries automatically. Best-in-class, but Chromium-only (caniuse).
  • Firefox / Safari — no auto-phrase, so they fall back to standard per-character wrapping under line-break: strict (kinsoku). This is the conventional way Japanese wraps in print and, crucially, never overflows the container. (An earlier revision used word-break: keep-all in the base rule; that forbids every break in space-less Japanese and caused horizontal overflow in Firefox/Safari — now fixed.)

Optional <wbr> phrase hints (works in every browser)

For key marketing/UI copy where phrase-aware breaks are wanted in all browsers, the author inserts <wbr> at phrase boundaries. Backpack detects it via :lang(ja):has(wbr) and switches that text to word-break: keep-all, making the <wbr> marks the only break points — so Firefox and Safari honour the same boundaries as Chromium. No consumer className is needed — <wbr> is content, and its presence is itself the opt-in signal.

// Safe everywhere; phrase-aware only in Chromium
<BpkText>プライスアラートを設定して東京行きのお得な航空券を見つけましょう</BpkText>

// Phrase-aware in every browser (incl. Firefox)
<BpkText>プライスアラートを<wbr />設定して<wbr />東京行きの<wbr />お得な航空券を<wbr />見つけましょう</BpkText>

Note: under keep-all, if the viewport is narrower than a single hinted phrase (e.g. narrower than プライスアラートを), that phrase still wraps mid-word (プライスアラート / を) rather than overflow the element — breaking is preferred over horizontal overflow.

Documented in the bpk-stylesheets README. See the bpk-stylesheets-fonts Larken story ("Japanese line-break validation") — compare the default vs <wbr>-hinted samples in Firefox.

Remember to include the following changes:

  • Ensure the PR title includes the name of the component you are changing so it's clear in the release notes for consumers of the changes in the version e.g [Clover-123][BpkButton] Updating the colour
  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Accessibility tests
    • The following checks were performed:
      • Ability to navigate using a keyboard only
      • Zoom functionality (Deque University explanation):
        • The page SHOULD be functional AND readable when only the text is magnified to 200% of its initial size
        • Pages must reflow as zoom increases up to 400% so that content continues to be presented in only one column i.e. Content MUST NOT require scrolling in two directions (both vertically and horizontally)
      • Ability to navigate using a screen reader only
  • Storybook examples created/updated
  • For breaking changes or deprecating components/properties, migration guides added to the description of the PR. If the guide has large changes, consider creating a new Markdown page inside the component's docs folder and link it here

Copilot AI review requested due to automatic review settings June 24, 2026 09:38
@IrinaWei IrinaWei added the major Breaking change label Jun 24, 2026

Copilot AI left a comment

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.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds global, locale-aware CSS line-breaking and wrapping behavior using :lang() selectors so non‑Latin scripts (CJK/Korean/Thai/RTL/Cyrillic) break more naturally without per-component changes.

Changes:

  • Introduces :lang()-scoped line-break, overflow-wrap, word-break, and hyphens rules for multiple scripts.
  • Adjusts CJK/Korean line-break behavior at the small-tablet breakpoint.

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

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

1 similar comment
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

skyscanner-backpack-bot Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Dev Release Published

Version: 43.0.0-dev-v28150129018.1

Install with:

npm install @skyscanner/[email protected]

You can also use the dev tag to install the latest dev release:

npm install @skyscanner/backpack-web@dev

Published from commit f129ca8 by IrinaWei.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

4 similar comments
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@gc-skyscanner GC Zhu (gc-skyscanner) added minor Non breaking change and removed major Breaking change labels Jul 17, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

IrinaWei and others added 7 commits July 27, 2026 15:51
Add :lang() CSS rules to font.scss so kinsoku shori (JIS X 4051) and
equivalent rules are enforced globally via the existing <html lang="...">
attribute — no per-component changes required.

Key decisions:
- line-break: strict for CJK/Korean fixes punctuation/particles appearing
  at line-start (を、に、の etc. must not begin a line)
- overflow-wrap: anywhere for CJK as last-resort fallback; preserves Latin
  brand names and URLs on mixed-script pages unlike word-break: break-all
- word-break: keep-all for Korean preserves syllable-block boundaries;
  overflow-wrap: break-word fallback handles 360–390px narrow viewports
- bpk-breakpoint-query-small-tablet (48rem) loosens line-break to loose for
  CJK/Korean to avoid uneven rag on narrow screens
- Thai uses break-all + overflow-wrap: anywhere — no word spaces, ICU
  dictionary failure leaves zero break points otherwise
- Arabic/Hebrew: overflow-wrap only; direction left to existing html[dir] RTL system
- Russian/Ukrainian: hyphens: auto degrades silently in Chrome

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
The base :lang(ja) rule used word-break: keep-all, which forbids all
breaks between space-less Japanese characters. Browsers without
word-break: auto-phrase (Firefox, Safari) fell back to keep-all and
overflowed the container instead of wrapping.

- Drop keep-all from the base rule so non-Chromium browsers wrap
  per-character under kinsoku (line-break: strict) — the conventional,
  overflow-safe Japanese fallback.
- Keep auto-phrase for Chromium via @supports.
- Add :lang(ja):has(wbr) → keep-all so author-inserted <wbr> phrase
  hints become the only break points, giving phrase-aware breaks in
  every browser (incl. Firefox) with no consumer className.
- Document the behaviour and <wbr> usage in the bpk-stylesheets README.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…r support docs

- Remove word-break: break-all and line-break: loose from :lang(th) — break-all overrides ICU dictionary word segmentation causing incorrect mid-character breaks; line-break only affects CJK kinsoku and has no effect on Thai
- Remove duplicate @include bpk-locale-line-breaks from larken.scss — font.scss already includes it, consumers importing both got duplicate rules
- Update README to qualify <wbr> phrase-break support as "all modern browsers (Chrome 105+, Safari 15.4+, Firefox 121+)" rather than "all browsers"

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@gc-skyscanner
GC Zhu (gc-skyscanner) force-pushed the fix/i18n-locale-line-break-rules branch from 96ec660 to a58245d Compare July 27, 2026 07:52
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@gc-skyscanner GC Zhu (gc-skyscanner) left a comment

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.

Confirmed with localisation team, LGTM

@gc-skyscanner
GC Zhu (gc-skyscanner) merged commit e0197c1 into main Jul 27, 2026
15 checks passed
@gc-skyscanner
GC Zhu (gc-skyscanner) deleted the fix/i18n-locale-line-break-rules branch July 27, 2026 08:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants