Open hediet opened 2 years ago
💯 for random Ids, but how would we adopt all existing translations to the new keys?
Btw I think changing the ID when the text changes is actually crucial because only that guarantees that translations are also updated, so maybe the ID should just be the hash of the text you type?
how would we adopt all existing translations to the new keys?
I don't see the problem here: We can do just an automated find+replace?
Btw I think changing the ID when the text changes is actually crucial because only that guarantees that translations are also updated
But this is already a much bigger problem in this example:
nls.localize('restart1', "Profile Extensions"),
When you want to change Profile Extensions
to Measure performance of Extensions
, how would you update the ID?
Also, I think this is a tooling issue of the translation system: Ideally, the translation system should prompt translators to re-translate a text when the English text changed significantly.
so maybe the ID should just be the hash of the text you type?
In that case, I would change the NLS system to use `${ID}${englishText}`
as translation key.
Then the ID is still independent, but all translations are lost when the text is changed.
FYI, according to this, the approximate expected value of how many random items you need to pick from a set of size n, is $\sqrt{n \pi / 2}$. Thus, if the random ID is a string of length 8 and uses lowercase+uppercase+numbers (which yields an alphabet of size 62), according to the formula, on average, you need to draw about 18.519.390 of such IDs until the first collision happens. If we add a random ID every minute, it is a 50:50 chance if a collision happens after 35 years or before.
I don't see the problem here: We can do just an automated find+replace?
Yeah what I meant is that this needs coordination across all published extensions that provide a translation for VSCode.
As for tooling, show a warning when the hash mismatches the value and don't allow to commit or fail the build.
Yeah what I meant is that this needs coordination across all published extensions that provide a translation for VSCode.
Not neccessarily, switching from meaningful to random IDs can happen incrementally, as you can just start using random IDs for all the new localizable strings immediately. From time to time, old IDs can then be replaced with random ones (both in code and all translations files) - this can be done by a tool and doesn't need to happen all at once.
As for tooling, show a warning when the hash mismatches the value and don't allow to commit or fail the build.
I wouldn't do that: If the ID is a deterministic hash from the text, you can also just use the text directly as ID.
I would rather suggest to use hash(id + text)
as actual translation key, so that the ID can still be used to differentiate equal texts, but changing the text invalidates all the translations.
To enable an incremental adoption, there could be a lookup for both hash(id + text)
and id
.
Keep in mind, the translators do get to see the id
and I would guess that they use that as some little bit of context when determining the right translation.
I do think for simpler cases localize('In order to profile extensions a restart is required.')
an id isn't useful... but something like: localize('Select a language')
can be ambiguous... whereas localize('coding language selection link', 'Select a language')
indicates that language
is a programming language and not a spoken language which matters in some spoken languages.
I like the idea of moving to a model where:
Problem
This is some source code that uses NLS:
These NLS calls use hand-crafted IDs. Very often, these IDs are meaningless and we need to add "comments" for the translators anyway. But still, it requires effort and mental energy to come up with these unique IDs.
Especially when other IDs are involved, their relationship is unclear:
Idea
To reduce the effort of coming up with NLS IDs, I suggest to use random computer generated ids.
Extensive tooling support would assist with generating such ids.
Implementation
With random IDs, the code could look like this:
Extensions could help to create such ids (for a different NLS call/syntax however, just as proof of concept here):
Especially with multi cursors, wrapping text in NLS calls would be very convenient.
Additional Thoughts
1) Why IDs and not just text? (
localize("In order to profile extensions a restart is required.")
)FYI @TylerLeonhardt