-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for spaces in Japanese unit patterns
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Locale } from '@phensley/cldr-core'; | ||
import { fixJapaneseUnits } from './japanese'; | ||
|
||
/** | ||
* Occasionally there are issues with the upstream data that | ||
* we need to resolve. We could do this via the patching feature | ||
* but since we're doing this internally that extra overhead is | ||
* unnecessary. | ||
*/ | ||
export const applyFixes = (locale: Locale, data: any) => { | ||
if (locale.tag.language() === 'ja') { | ||
fixJapaneseUnits(data); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { UnitLength } from '@phensley/cldr-core'; | ||
|
||
/** | ||
* Remove spaces in Japanese unit patterns. | ||
* | ||
* Our Japanese translators indicate there should be no spaces in these | ||
* unit patterns, for either standalone or mid-sentence contexts. | ||
* | ||
* See: | ||
* - https://unicode-org.atlassian.net/browse/CLDR-10556?focusedCommentId=116703 | ||
* - https://unicode-org.atlassian.net/browse/CLDR-10715 | ||
*/ | ||
export const fixJapaneseUnits = (data: any) => { | ||
fix(data, 'long'); | ||
fix(data, 'short'); | ||
fix(data, 'narrow'); | ||
}; | ||
|
||
const fix = (data: any, length: UnitLength) => { | ||
const units = data.Units[length].unitPattern.other; | ||
for (const key of Object.keys(units)) { | ||
const value = units[key]; | ||
const i = value.indexOf('{0}'); | ||
// Ensure no space separates the unit from the quantity "{0}" in the pattern | ||
units[key] = value.slice(0, i).trim() + '{0}' + value.slice(i + 3).trim(); | ||
} | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getCLDR } from './_helpers'; | ||
|
||
test('units', () => { | ||
const framework = getCLDR(); | ||
const api = framework.get('ja'); | ||
let s: string; | ||
|
||
s = api.Units.formatQuantity({ value: 5, unit: 'hour' }, { length: 'long' }); | ||
expect(s).toEqual('5時間'); | ||
}); |