Skip to content

refactor(util): read a locale tag in one place - #1272

Merged
andiwand merged 2 commits into
mainfrom
refactor/locale-util
Oct 25, 2026
Merged

andiwand merged 2 commits into
mainfrom
refactor/locale-util

Conversation

@andiwand

@andiwand andiwand commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Follows #1270.

Summary

Four places read the BCP 47 tag of a locale, each with its own rules:

place before
formula::language_of (function names) lowered the case, mapped no to nb, and matched only the exact tag pt-BR
number_format::symbols_of (decimal sign, grouping) case-sensitive, and took the last subtag as the region
names_of (month names) and boolean_words case-sensitive, mapped no to nb

util::locale::LanguageTag::parse (new src/odr/internal/util/locale_util.{hpp,cpp}) now reads the tag once:

  • the language in lowercase, no as nb
  • a script of four letters in title case, which is no longer read as a region
  • a region of two letters or three digits in uppercase
  • - or _ between the subtags, in any case
  • a variant and what follows a singleton (-u-, -x-) dropped

The callers use it, so the four no → nb mappings and the "no" entry of the grouping table go away. The LibreOffice key pt-BR stays in the formula code, but it now tests the language and the region.

Lowercase. lower_function_letter lowercased only the letters of the generated name table, and mapped the Turkish I for same_name. It is gone, and the formula table and its generator are as they were before #1270:

  • util::locale::to_lower(letter, language) lowercases any letter from lowercase_table.cpp: the 1460 Unicode letters whose lowercase is one code point. tools/util/generate_lowercase.py writes it from the Unicode data of Python (16.0.0 here), and adds the simple lowercase i of İ. In tr and az, I becomes ı.
  • util::locale::equals_ignore_case(a, b, language) compares two UTF-8 strings with it, in place of same_name.
  • The formula module grows by 15 KB (639885 to 655277 bytes).

What a user sees: pt-Latn-BR and pt_br take the Brazilian function names, zh-Hans has no region, and DE-ch and de_CH group with an apostrophe.

Test

  • New LocaleUtil.* (9 tests): case, _, script, variant, extension, Norwegian, empty, the lowercase of Latin, Greek, Cyrillic and an astral letter, the Turkish I, and a compare of UTF-8.
  • NumberFormat and FormulaWriter check the new tags at their callers: COLUMN is COL in Portugal and COLUNA in Brazil.
  • The locale, formula, number format, sheet and html gtests pass, and so do the wasm tests (83) and the sheet pages locale, formula-input, formula-words and dates.
  • A -Wall -Wextra -Werror check of the three changed sources is clean, and clang-tidy reports nothing on them.

Review fixes

  • Rebased onto main after fix(html): keep a generic font family a keyword #1271. No code change was needed.
  • I checked that no other code reads a BCP 47 tag: the page scripts give data-odr-locale to Intl inside a try, and the [$-407] of a number format code is an LCID, which keeps its own path. The decoders write the tag with -.
  • Tested: the locale, number format, formula and html gtests.

The formula names, the number symbols, the month names and the boolean
words each read the BCP 47 tag of a locale on their own, with different
rules: one lowered the case, one took the last subtag as the region, and
three of four mapped `no` to `nb`. util::locale::LanguageTag::parse now
reads the language, the script and the region once, in any case and with
`-` or `_`, and drops a variant and an extension.

So `pt-Latn-BR` takes the Brazilian names, `zh-Hans` has no region, and
`DE-ch` and `de_CH` group with an apostrophe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
@andiwand
andiwand force-pushed the refactor/locale-util branch from 178f178 to 109f018 Compare October 25, 2026 10:09
lower_function_letter lowercased only the letters of the generated name
table and mapped the Turkish I, so it could not leave the formula code.
util::locale::to_lower now lowercases any letter from a table of the 1460
Unicode letters whose lowercase is one code point, which
tools/util/generate_lowercase.py writes, and takes the dotless i of tr and
az. util::locale::equals_ignore_case compares two UTF-8 strings with it,
and the formula code uses it in place of same_name. The formula table and
its generator are as they were before #1270.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YHNzLmVv1mFWfPitHASucN
@andiwand
andiwand merged commit 9417999 into main Oct 25, 2026
4 of 17 checks passed
@andiwand
andiwand deleted the refactor/locale-util branch October 25, 2026 10:17
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.

1 participant