Ticket #4418: 4418_duration_l18n.patch

File 4418_duration_l18n.patch, 5.9 KB (added by Imarok, 7 years ago)

Fixes 1) by distinguishing between the localization of a time and the localitzation of a duration

  • binaries/data/mods/public/gui/common/functions_utility.js

     
    132132        var format = translate("mm:ss");
    133133    else
    134134        var format = translate("HH:mm:ss");
    135     return Engine.FormatMillisecondsIntoDateString(time, format);
     135    return Engine.FormatMillisecondsIntoDurationString(time, format);
    136136}
    137137
    138138function removeDupes(array)
  • source/i18n/L10n.cpp

     
    375375    return std::string(utf8Date, sink.NumberOfBytesWritten());
    376376}
    377377
    378 std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString) const
     378std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString, bool isDuration) const
    379379{
    380380    UErrorCode status = U_ZERO_ERROR;
    381381    UnicodeString dateString;
     
    386386    if (U_FAILURE(status))
    387387        LOGERROR("Error creating SimpleDateFormat: %s", u_errorName(status));
    388388
    389     const TimeZone* timeZone = TimeZone::createDefault();
     389    const TimeZone* timeZone = isDuration ? TimeZone::getGMT() : TimeZone::createDefault();
    390390
    391391    status = U_ZERO_ERROR;
    392392    Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status);
  • source/i18n/L10n.h

     
    435435     *        symbols. Usually, you internationalize the format string and
    436436     *        get it translated before you pass it to
    437437     *        FormatMillisecondsIntoDateString().
     438     * @param isDuration Boolean if the date is a duration don't convert to
     439     *        the local timezone; default: false
    438440     * @return String containing the specified date with the specified date
    439441     *         format.
    440442     *
     
    441443     * @sa http://en.wikipedia.org/wiki/Unix_time
    442444     * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
    443445     */
    444     std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString) const;
     446    std::string FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString, bool isDuration = false) const;
    445447
    446448    /**
    447449     * Returns the specified floating-point number as a string, with the number
  • source/i18n/scripting/JSInterface_L10n.cpp

     
    7474    return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString)));
    7575}
    7676
     77// Return a localized version of a duration given in milliseconds.
     78std::wstring JSI_L10n::FormatMillisecondsIntoDurationString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString)
     79{
     80    return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString), true));
     81}
     82
    7783// Return a localized version of the given decimal number.
    7884std::wstring JSI_L10n::FormatDecimalNumberIntoString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), double number)
    7985{
     
    160166    scriptInterface.RegisterFunction<std::wstring, std::wstring, &TranslateLines>("TranslateLines");
    161167    scriptInterface.RegisterFunction<std::vector<std::wstring>, std::vector<std::wstring>, &TranslateArray>("TranslateArray");
    162168    scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDateString>("FormatMillisecondsIntoDateString");
     169    scriptInterface.RegisterFunction<std::wstring, UDate, std::wstring, &FormatMillisecondsIntoDurationString>("FormatMillisecondsIntoDurationString");
    163170    scriptInterface.RegisterFunction<std::wstring, double, &FormatDecimalNumberIntoString>("FormatDecimalNumberIntoString");
    164171
    165172    scriptInterface.RegisterFunction<std::vector<std::string>, &GetSupportedLocaleBaseNames>("GetSupportedLocaleBaseNames");
  • source/i18n/scripting/JSInterface_L10n.h

     
    175175    std::wstring FormatMillisecondsIntoDateString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString);
    176176
    177177    /**
     178    * Returns the specified duration using the specified date format.
     179    *
     180    * This is a JavaScript interface to
     181    * L10n::FormatMillisecondsIntoDateString().
     182    *
     183    * @param pCxPrivate JavaScript context.
     184    * @param milliseconds Date specified as a UNIX timestamp in milliseconds
     185    *        (not seconds). If you have a JavaScript @c ​Date object, you can
     186    *        use @c ​Date.getTime() to obtain the UNIX time in milliseconds.
     187    * @param formatString Date format string defined using ICU date formatting
     188    *        symbols. Usually, you internationalize the format string and
     189    *        get it translated before you pass it to
     190    *        FormatMillisecondsIntoDateString().
     191    * @return String containing the specified date with the specified date
     192    *         format.
     193    *
     194    * @sa http://en.wikipedia.org/wiki/Unix_time
     195    * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
     196    */
     197    std::wstring FormatMillisecondsIntoDurationString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, const std::wstring& formatString);
     198
     199    /**
    178200     * Returns the specified floating-point number as a string, with the number
    179201     * formatted as a decimal number using the
    180202     * @link L10n::GetCurrentLocale() current locale@endlink.