Changeset View
Standalone View
binaries/data/mods/mod/gui/common/l10n.js
/** | /** | ||||
* @param filesize - In bytes. | |||||
* @return Object with quantized filesize and suitable unit of size. | |||||
*/ | |||||
function filesizeToObj(filesize) | |||||
{ | |||||
// We are unlikely to download files measured in units greater than GiB. | |||||
let units = [ | |||||
translateWithContext("filesize unit", "B"), | |||||
translateWithContext("filesize unit", "KiB"), | |||||
translateWithContext("filesize unit", "MiB"), | |||||
translateWithContext("filesize unit", "GiB") | |||||
]; | |||||
let i = 0; | |||||
while (i < units.length - 1) | |||||
{ | |||||
if (filesize < 1024) | |||||
break; | |||||
filesize /= 1024; | |||||
++i; | |||||
} | |||||
return { | |||||
"filesize": filesize.toFixed(i == 0 ? 0 : 1), | |||||
"unit": units[i] | |||||
}; | |||||
} | |||||
function filesizeToString(filesize) | |||||
{ | |||||
// Translation: For example: 123.4 KiB | |||||
return sprintf(translate("%(filesize)s %(unit)s"), filesizeToObj(filesize)); | |||||
} | |||||
/** | |||||
* Convert time in milliseconds to [HH:]mm:ss string representation. | * Convert time in milliseconds to [HH:]mm:ss string representation. | ||||
* | * | ||||
* @param time Time period in milliseconds (integer) | * @param time Time period in milliseconds (integer) | ||||
* @return String representing time period | * @return String representing time period | ||||
*/ | */ | ||||
function timeToString(time) | function timeToString(time) | ||||
{ | { | ||||
return Engine.FormatMillisecondsIntoDateStringGMT(time, time < 1000 * 60 * 60 ? | return Engine.FormatMillisecondsIntoDateStringGMT(time, time < 1000 * 60 * 60 ? | ||||
Show All 19 Lines | |||||
* Translates the specified English message into the current language. | * Translates the specified English message into the current language. | ||||
*/ | */ | ||||
function translate(message) | function translate(message) | ||||
{ | { | ||||
if (!g_Translations[message]) | if (!g_Translations[message]) | ||||
g_Translations[message] = Engine.Translate(message); | g_Translations[message] = Engine.Translate(message); | ||||
return g_Translations[message]; | return g_Translations[message]; | ||||
} | } | ||||
leper: Now lacks any explanation for the quite random cut-off.
I'm not sure why units need to be… | |||||
Not Done Inline ActionsYou mean why stopping at GiB? If yes done. Itms: You mean why stopping at `GiB`? If yes done. | |||||
Not Done Inline ActionsYes, see the comment that was there in the original version of the code, then was removed, then got added back... leper: Yes, see the comment that was there in the original version of the code, then was removed, then… | |||||
/** | /** | ||||
* Translates the specified English message into the current language for the specified number. | * Translates the specified English message into the current language for the specified number. | ||||
*/ | */ | ||||
Done Inline ActionsShould probably be [HH:] unless this differs with the code for a reason. leper: Should probably be `[HH:]` unless this differs with the code for a reason. | |||||
function translatePlural(singularMessage, pluralMessage, number) | function translatePlural(singularMessage, pluralMessage, number) | ||||
Done Inline ActionsThis conflicts with timeToString in functions_utility. (The game duration now says "10 seconds", etc.) temple: This conflicts with `timeToString` in functions_utility. (The game duration now says "10… | |||||
Not Done Inline ActionsUsing the other one, as hours should be sufficient and translations should be of better quality. Itms: Using the other one, as hours should be sufficient and translations should be of better quality. | |||||
Not Done Inline Actions(In this particular case we don't expect any translation to actually be different, e.g. no one puts seconds before minutes.) temple: (In this particular case we don't expect any translation to actually be different, e.g. no one… | |||||
Not Done Inline ActionsBut some translators might attempt to add a prefix, between them. So you could get XX hours NN minutes, or similar. Not that I think this will work properly. In case someone wants another example of weird date/time formats that some might be inclined to use would be the whole am/pm mess. leper: But some translators might attempt to add a prefix, between them. So you could get XX hours NN… | |||||
{ | { | ||||
if (!g_PluralTranslations[singularMessage]) | if (!g_PluralTranslations[singularMessage]) | ||||
g_PluralTranslations[singularMessage] = {}; | g_PluralTranslations[singularMessage] = {}; | ||||
if (!g_PluralTranslations[singularMessage][number]) | if (!g_PluralTranslations[singularMessage][number]) | ||||
g_PluralTranslations[singularMessage][number] = Engine.TranslatePlural(singularMessage, pluralMessage, number); | g_PluralTranslations[singularMessage][number] = Engine.TranslatePlural(singularMessage, pluralMessage, number); | ||||
Done Inline ActionsEven though this was just moved, I suppose having a translation comment for the format (we do in other places) might be nice. leper: Even though this was just moved, I suppose having a translation comment for the format (we do… | |||||
Not Done Inline ActionsI have a patch at D1116. temple: I have a patch at D1116. | |||||
Not Done Inline ActionsThis looks nice but I'm starting to be a bit tired of rebases... I fixed this and I'd push D1116 to A24 out of pure laziness. Or if you really want it in I'd be thrilled if you could rebase it upon mod.io rather than the opposite. Itms: This looks nice but I'm starting to be a bit tired of rebases... I fixed this and I'd push… | |||||
Not Done Inline ActionsThe important part of the translation comment is to point to the icu docs that list the allowed characters. leper: The important part of the translation comment is to point to the icu docs that list the allowed… | |||||
return g_PluralTranslations[singularMessage][number]; | return g_PluralTranslations[singularMessage][number]; | ||||
} | } | ||||
/** | /** | ||||
* Translates the specified English message into the current language for the specified context. | * Translates the specified English message into the current language for the specified context. | ||||
*/ | */ | ||||
function translateWithContext(context, message) | function translateWithContext(context, message) | ||||
{ | { | ||||
if (!g_TranslationsWithContext[context]) | if (!g_TranslationsWithContext[context]) | ||||
g_TranslationsWithContext[context] = {}; | g_TranslationsWithContext[context] = {}; | ||||
if (!g_TranslationsWithContext[context][message]) | if (!g_TranslationsWithContext[context][message]) | ||||
g_TranslationsWithContext[context][message] = Engine.TranslateWithContext(context, message); | g_TranslationsWithContext[context][message] = Engine.TranslateWithContext(context, message); | ||||
return g_TranslationsWithContext[context][message]; | return g_TranslationsWithContext[context][message]; | ||||
} | } | ||||
Done Inline ActionsDon't we have functions we could use for that already? If not, doesn't ICU expose something nice? Also I'm not sure if reusing the structure of the other function for this makes a lot of sense. leper: Don't we have functions we could use for that already? If not, doesn't ICU expose something… | |||||
/** | /** | ||||
* Translates the specified English message into the current language for the specified context and number. | * Translates the specified English message into the current language for the specified context and number. | ||||
*/ | */ | ||||
function translatePluralWithContext(context, singularMessage, pluralMessage, number) | function translatePluralWithContext(context, singularMessage, pluralMessage, number) | ||||
{ | { | ||||
if (!g_PluralTranslationsWithContext[context]) | if (!g_PluralTranslationsWithContext[context]) | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |
Now lacks any explanation for the quite random cut-off.
I'm not sure why units need to be translated, but I guess different alphabets might be a valid reason for that.