Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Brendan js feedback
  • Loading branch information
exterkamp committed Jun 26, 2019
commit 2c3dfc2029521cac4390d1fec8f73c56e9ce9e94
2 changes: 1 addition & 1 deletion lighthouse-core/lib/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function _formatIcuMessage(locale, icuMessageId, fallbackMessage, values) {
const messageForMessageFormat = localeMessage || fallbackMessage;
if (messageForMessageFormat === undefined) throw new Error(_ICUMsgNotFoundMsg);
// when using accented english, force the use of a different locale for number formatting
const localeForMessageFormat = locale === 'en-XA' || locale === 'en-XL' ? 'de-DE' : locale;
const localeForMessageFormat = (locale === 'en-XA' || locale === 'en-XL') ? 'de-DE' : locale;
// pre-process values for the message format like KB and milliseconds
const valuesForMessageFormat = _preprocessMessageValues(messageForMessageFormat, values);

Expand Down
25 changes: 14 additions & 11 deletions lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,25 @@ function createPsuedoLocaleStrings(strings) {
const psuedoLocalizedString = [];
let braceCount = 0;
let useHatForAccentMark = true;
for (let i = 0; i < message.length; i++) {
const char = message.substr(i, 1);
for (const char of message) {
psuedoLocalizedString.push(char);
// Don't touch the characters inside braces
if (char === '{') {
braceCount++;
} else if (char === '}') {
braceCount--;
// Hack to ignore the nested {plural{ICU}braces}.
// ex: "{itemCount, plural, =1 {1 l̂ín̂ḱ f̂óûńd̂} other {# ĺîńk̂ś f̂óûńd̂}}"
// ex: "{itemCount, plural, =1 {1 l̂ín̂ḱ {nested_replacement} f̂óûńd̂} other {# ĺîńk̂ś {nested_replacement} f̂óûńd̂}}"
} else if (braceCount % 2 === 0) {
if (/[a-z]/i.test(char)) {
psuedoLocalizedString.push(useHatForAccentMark ? `\u0302` : `\u0301`);
useHatForAccentMark = !useHatForAccentMark;
}
}

// Hack to not change {plural{ICU}braces} nested an odd number of times.
// ex: "{itemCount, plural, =1 {1 link found} other {# links found}}"
// becomes "{itemCount, plural, =1 {1 l̂ín̂ḱ f̂óûńd̂} other {# ĺîńk̂ś f̂óûńd̂}}"
// ex: "{itemCount, plural, =1 {1 link {nested_replacement} found} other {# links {nested_replacement} found}}"
// becomes: "{itemCount, plural, =1 {1 l̂ín̂ḱ {nested_replacement} f̂óûńd̂} other {# ĺîńk̂ś {nested_replacement} f̂óûńd̂}}"
if (braceCount % 2 === 1) continue;

// Add diacritical marks to the preceding letter, alternating between a hat ( ̂) and an acute (´).
if (/[a-z]/i.test(char)) {
psuedoLocalizedString.push(useHatForAccentMark ? `\u0302` : `\u0301`);
useHatForAccentMark = !useHatForAccentMark;
}
}

Expand Down