Repository navigation
fix: numbers typed are read in the viewer's locale, whole or not at all - #37
Open
pierreneter wants to merge 1 commit into
Open
pierreneter wants to merge 1 commit into
pierreneter wants to merge 1 commit into
Conversation
…ll (#17) `locale` (DocViewer prop, `<office-viewer locale>`, `mount()`, the third argument of `xlsx.set`) is the BCP 47 tag the numbers a person types are read in: cells (numbers, percentages, amounts), the font size box, the Page setup margins and column spacing, the Header & footer size. One parser in the core (src/core/number-input.ts) takes the separators, signs and digits from Intl.NumberFormat.formatToParts: `1,5` and `1.234,5` are numbers in de-DE. The whole text is one number or none: a separator that is neither the decimal one nor a well-formed grouping makes the text no number (`1.5` in de-DE, `1,5` in en-US), and a prefix is never read (`12pt` keeps the font size it had). Grouping: the locale's character between groups of its sizes (3, or 3 then 2 in India), every space where it groups with a space, both apostrophes in Swiss German. Without a locale every input reads as before (a decimal point, commas by thousands), whatever the browser's language; the font size box alone still reads a decimal comma too (`12,5` is 12.5, as since c491ea7), a size needing no grouping, but not `1,234` or `1,2,5`. Saved values are numbers and formulas are not localized. A number edited again shows the locale's decimal separator, which reads back as the same number. A shared cell edit carries the locale, so every participant and `compact` read it alike. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17.
Numbers typed by a user are read in the viewer's locale, and the whole input must be a number: a numeric prefix is never accepted.
What changes
localeprop onDocViewerand alocaleembed attribute: a BCP 47 tag. Without it, input is read exactly as before (decimal point, comma grouping), and the browser's language is never used implicitly.src/core/number-input.ts, pure and DOM-free. It takes the separators, group sizes, minus sign, percent sign and digits fromIntl.NumberFormat(locale).formatToParts. It is used by:parseInput): plain numbers, percentages, amounts with a currency sign;1,5underde-DEreads back as 1.5, not as text or 15.setoperation carries the canonical locale tag, so every replica andcompactread a typed value the same way.Rules
The full rules are in
docs/features.md#numbers-typed-in-a-locale:de-CH) are accepted.1,5inen-US, and1.5or1,234.5inde-DE.1.234inde-DEis 1234, mirroring1,234without a locale.12,5→ 12.5), since a size needs no grouping. Whole-input validation still applies, so12pt,1.2.5and1,234are refused and the box shows the previous size.Relation to #6
The prop uses the same name, type, tag validation and embed attribute as #6. To land #6 on top:
LocaleContextprovider inDocViewer;useLocale = () => useStrings().locale;localedoc rows.strings={de}then makes input German as well.Not covered
1.5); only the editor shows1,5.DocViewerhave no public way to set the input locale until feat(viewer): translatable UI texts: strings table, locale and strings props #6'sStringsProviderlands.Tests
Run in the Linux test VM with Bun 1.4.4. All results below are on the final commit.
New tests:
test/number-input.test.tsx:numberTextand the parser for about 3,000 values in each of 10 locales;test/xlsx-locale.test.ts:main, pinning today's behaviour;de-DEinput saved as<v>1.5</v>, reopened and compared;xlsx.spec.ts: a cell and the font size box underde-DEand under the default;docx-page.spec.ts: margins underde-DE;embed.spec.ts: thelocaleattribute, including its removal.Results:
bun teste2e/xlsx.spec.tse2e/docx.spec.tse2e/docx-page.spec.tse2e/embed.spec.tsThe
viewer,sdk,collabanddocx-hfe2e specs passed on the previous revision of this commit.The new
de-DE, collaboration, size-box and embed tests fail onmain.🤖 Generated with Claude Code