MCPcopy Index your code
hub / github.com/messageformat/messageformat / setLocale

Method setLocale

packages/messageformat/src/compiler.js:196–214  ·  view source on GitHub ↗
(key, ord)

Source from the content-addressed store, hash-verified

194 }
195
196 setLocale(key, ord) {
197 const prev = this.runtimeIncludes(key, 'locale');
198 const { getCardinal, getPlural, isDefault } = this.plural;
199 let pf;
200 if (!ord && isDefault && getCardinal) {
201 if (prev) return;
202 pf = n => getCardinal(n);
203 pf.module = CARDINAL_MODULE;
204 pf.toString = () => String(getCardinal);
205 } else {
206 // overwrite a previous cardinal-only locale function
207 if (prev && (!isDefault || prev.module === PLURAL_MODULE)) return;
208 pf = (n, ord) => getPlural(n, ord);
209 pf.module = isDefault ? PLURAL_MODULE : getPlural.module;
210 pf.toString = () => String(getPlural);
211 }
212 pf.type = 'locale';
213 this.runtime[key] = pf;
214 }
215
216 setRuntimeFn(key) {
217 if (this.runtimeIncludes(key, 'runtime')) return;

Callers 1

tokenMethod · 0.95

Calls 2

runtimeIncludesMethod · 0.95
getPluralFunction · 0.85

Tested by

no test coverage detected