Changeset View
Standalone View
binaries/data/mods/public/gui/common/functions_utility.js
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function translateMapTitle(mapTitle) | function translateMapTitle(mapTitle) | ||||
{ | { | ||||
return mapTitle == "random" ? translateWithContext("map selection", "Random") : translate(mapTitle); | return mapTitle == "random" ? translateWithContext("map selection", "Random") : translate(mapTitle); | ||||
} | } | ||||
/** | /** | ||||
* Convert time in milliseconds to [hh:]mm:ss string representation. | * Convert time in milliseconds to m:ss or H: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 ? | ||||
translate("mm:ss") : translate("HH:mm:ss")); | // Translation: Format of the time elapsed or remaining, for game durations, ceasefire and wonder-victory countdowns, etc. | ||||
// For a list of symbols that you can use, see: | |||||
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | |||||
translateWithContext("countdown format for times less than one hour", "m:ss") : | |||||
// Translation: Format of the time elapsed or remaining, for game durations, ceasefire and wonder-victory countdowns, etc. | |||||
// For a list of symbols that you can use, see: | |||||
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | |||||
translateWithContext("countdown format for times greater than one hour", "H:mm:ss")); | |||||
elexis: This function is currently used in three cases:
1) matchtime elapsed (replay, savegame, lobby… | |||||
templeAuthorUnsubmitted Not Done Inline ActionsYes, we should be clearer here that this is a duration rather than a time like "one o'clock". I guess it's possible that in different places we'd want to show the duration differently. For example in the replay menu maybe we only want to show hours:minutes rather than seconds too. But I'm happy with the current one-size-fits-all approach. temple: Yes, we should be clearer here that this is a duration rather than a time like "one o'clock". | |||||
elexisUnsubmitted Not Done Inline ActionsOk to keep it. elexis: Ok to keep it. | |||||
} | |||||
function chatTimestampToString(time) | |||||
{ | |||||
return sprintf( | |||||
// Translation: Time prefix as shown in the chat in the lobby, game setup, and session (when you enable it in the options page). | |||||
translate("\\[%(time)s]"), { | |||||
Not Done Inline ActionsWould be nice if it could become [%(time)s] so that the translation folks don't have to take care of escaping it (and don't need to understand why there are those backslashes to begin with). But that will need an escapeText call to compensate and warn(escapeText(escapeText("[asd]"))); shows \\\[asd], so we'd have to ensure that either nothing calling this function adds another escapeText, or add the escapeText in every caller. Or leave as is. Pick your poison. elexis: Would be nice if it could become `[%(time)s]` so that the translation folks don't have to take… | |||||
// Translation: Format of the local time as shown in the chat in the lobby, game setup, and session (when you enable it in the options page). | |||||
// For a list of symbols that you can use, see: | |||||
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | |||||
"time": Engine.FormatMillisecondsIntoDateStringLocal(time, translateWithContext("chat timestamp format", "HH:mm")) | |||||
elexisUnsubmitted Not Done Inline Actions"chat timestamp" elexis: "chat timestamp" | |||||
templeAuthorUnsubmitted Not Done Inline ActionsYeah, I guess I don't need to say "format" in all of these. temple: Yeah, I guess I don't need to say "format" in all of these. | |||||
elexisUnsubmitted Not Done Inline Actions(when you enable it in the options page). were unneeded elexis: `(when you enable it in the options page). ` were unneeded | |||||
}); | |||||
} | } | ||||
Not Done Inline ActionsI would prefer to kill this file due to a lack of definition which files it should contain. elexis: I would prefer to kill this file due to a lack of definition which files it should contain.
How… | |||||
function removeDupes(array) | function removeDupes(array) | ||||
{ | { | ||||
// loop backwards to make splice operations cheaper | // loop backwards to make splice operations cheaper | ||||
var i = array.length; | var i = array.length; | ||||
while (i--) | while (i--) | ||||
{ | { | ||||
if (array.indexOf(array[i]) != i) | if (array.indexOf(array[i]) != i) | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |
This function is currently used in three cases:
I don't know if people on transifex would want to use two different strings (elapsed, countdown) if they knew about the string mechanics to begin with.
Nor do I know whether they would like to distinguish even further.
But the name timeToString indiciates to the programmer that he can always use this when passing a time.
Perhaps a elapsedTimeString and a countdownTimeString with the context countdown format and elapsed time format might make cleaner code and transifex material?