Bug 1301312 - Part 1: Localize AM/PM strings for <input type=time>. r=gandalf,mconley

MozReview-Commit-ID: 2QycAbnHmHv

--HG--
extra : rebase_source : cbbd9ce4ccebcf611d5ccd908536c107424e3fb4
This commit is contained in:
Jessica Jong 2017-03-06 14:43:12 +08:00
Родитель 08043d3e1f
Коммит b4fc37baaf
1 изменённых файлов: 43 добавлений и 3 удалений

Просмотреть файл

@ -444,10 +444,16 @@
<implementation>
<constructor>
<![CDATA[
// TODO: Bug 1301312 - localization for input type=time input.
const kDefaultAMString = "AM";
const kDefaultPMString = "PM";
let { amString, pmString } =
this.getStringsForLocale(this.mLocales);
this.mAMIndicator = amString || kDefaultAMString;
this.mPMIndicator = pmString || kDefaultPMString;
this.mHour12 = true;
this.mAMIndicator = "AM";
this.mPMIndicator = "PM";
this.mPlaceHolder = "--";
this.mSeparatorText = ":";
this.mMillisecSeparatorText = ".";
@ -477,6 +483,12 @@
document.getAnonymousElementByAttribute(this, "anonid", "input-three");
this.mDayPeriodField.classList.remove("numeric");
let dayPeriodLength =
Math.max(this.mAMIndicator.length, this.mPMIndicator.length);
this.mDayPeriodField.size = dayPeriodLength;
this.mDayPeriodField.maxLength = dayPeriodLength;
this.mHourField.placeholder = this.mPlaceHolder;
this.mMinuteField.placeholder = this.mPlaceHolder;
this.mDayPeriodField.placeholder = this.mPlaceHolder;
@ -552,6 +564,33 @@
</body>
</method>
<method name="getStringsForLocale">
<parameter name="aLocales"/>
<body>
<![CDATA[
this.log("getStringsForLocale: " + aLocales);
let intlUtils = window.intlUtils;
if (!intlUtils) {
return {};
}
let amString, pmString;
let keys = [ "dates/gregorian/dayperiods/am",
"dates/gregorian/dayperiods/pm" ];
let result = intlUtils.getDisplayNames(this.mLocales, {
style: "short",
keys
});
[ amString, pmString ] = keys.map(key => result.values[key]);
return { amString, pmString };
]]>
</body>
</method>
<method name="setFieldsFromInputValue">
<body>
<![CDATA[
@ -1024,6 +1063,7 @@
<![CDATA[
this.DEBUG = false;
this.mInputElement = this.parentNode;
this.mLocales = window.getAppLocalesAsBCP47();
this.mMin = this.mInputElement.min;
this.mMax = this.mInputElement.max;