-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n: placeholders #9114
i18n: placeholders #9114
Changes from 3 commits
656acce
fc762a5
d1cdeab
74e11c1
981e028
6d2dd5d
f22ee1b
c66c0c6
70a5a07
a7fc83a
0de5485
f8650eb
37dc2ae
58c7ded
ad01bdd
4182889
8b0f8ea
ddf8171
705ffb6
902c2f7
4507138
29e29df
393beb6
799084c
86e1593
6160402
02e8977
f5083b8
5aca05a
ee3e235
6b8297d
77fcd92
7252f3d
d4dd3ac
996ee5c
4ff414a
588f574
2b17130
570a6cc
dcc7cc7
7743cda
ce01c75
dea280a
7f89ccf
cf42496
d156737
89410f8
ea3616b
3d40437
bc2b8f3
92cafeb
3d746d6
5ad0dff
c2e4ce5
5dd3e07
6eef366
a35a45e
13d0f02
b34ef95
48283f4
95527d5
327c7db
b006cf7
51cbb78
37be64c
d2a8326
be426b8
125cb1d
b95b96b
90efcff
6e6ef24
6a9ef28
7762381
6c19a17
be34f7e
23a68d5
3685dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,7 +174,23 @@ const _icuMessageInstanceMap = new Map(); | |
*/ | ||
function _formatIcuMessage(locale, icuMessageId, icuMessage, values) { | ||
const localeMessages = LOCALES[locale]; | ||
const localeMessage = localeMessages[icuMessageId] && localeMessages[icuMessageId].message; | ||
let localeMessage = localeMessages[icuMessageId] && localeMessages[icuMessageId].message; | ||
// lets try to replace some things :o | ||
const placeholders = localeMessages[icuMessageId] && localeMessages[icuMessageId].placeholders; | ||
if (placeholders) { | ||
console.log('placeholders!'); | ||
// do some regex | ||
Object.entries(placeholders).forEach(entry => { | ||
const key = entry[0]; | ||
const value = entry[1]; | ||
//use key and value here | ||
let regexStr = `\$${key}\$`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll definitely want a |
||
console.log(key, value, regexStr); | ||
localeMessage = localeMessage.replace(regexStr, value.content); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe to avoid the issue with positional replacements ( |
||
console.log(localeMessage); | ||
}); | ||
} | ||
|
||
// fallback to the original english message if we couldn't find a message in the specified locale | ||
// better to have an english message than no message at all, in some number cases it won't even matter | ||
const messageForMessageFormat = localeMessage || icuMessage; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a pretty unfortunate syntax. Maybe we want to come up with something that expands to this in
collect-strings.js
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, I meant this as a super low priority idea that we can think about while we do everything else first and implement it later if there's a nice fix. It kind of sucks to look at/edit but we could live with it if need be (we may need a test to make sure a typo in one of the contents doesn't accidentally break a link)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was also my thought. This is super heavyweight to have in each
.js
file. I can try to experiment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just keep it as
[some text {name} or even placeholders](url)
and expand it to additional placeholders in collect strings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like auto convert
[
and](url)
intolink_start
link_end
in collect strings?I worry about making special cases, adding unseen complexity behind the scenes. I think part of the positives of a change like this is that it removes all ambiguity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah - I think that'd be dope