Skip to content

Commit d388141

Browse files
feat(mf2)!: Drop u:locale option (unicode-org/message-format-wg#1012)
1 parent b4abce5 commit d388141

File tree

5 files changed

+4
-37
lines changed

5 files changed

+4
-37
lines changed

mf2/messageformat/src/resolve/format-markup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function formatMarkup(
1414
if (options?.size) {
1515
part.options = {};
1616
for (const [name, value] of options) {
17-
if (name === 'u:dir' || name === 'u:locale') {
17+
if (name === 'u:dir') {
1818
const msg = `The option ${name} is not valid for markup`;
1919
const optSource = getValueSource(value);
2020
ctx.onError(new MessageResolutionError('bad-option', msg, optSource));

mf2/messageformat/src/resolve/function-context.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,12 @@ import { Options } from '../data-model/types.ts';
66
export class MessageFunctionContext {
77
#ctx: Context;
88
#litKeys: Set<string> | undefined;
9-
#locales: Intl.Locale[];
109
readonly dir: 'ltr' | 'rtl' | 'auto' | undefined;
1110
readonly id: string | undefined;
1211
readonly source: string;
1312
constructor(ctx: Context, source: string, options?: Options) {
1413
this.#ctx = ctx;
1514

16-
this.#locales = ctx.locales;
17-
const localeOpt = options?.get('u:locale');
18-
if (localeOpt) {
19-
let rl = resolveValue(ctx, localeOpt);
20-
try {
21-
if (typeof rl === 'object' && typeof rl?.valueOf === 'function') {
22-
rl = rl.valueOf();
23-
}
24-
this.#locales = Array.isArray(rl)
25-
? rl.map(lc => new Intl.Locale(lc))
26-
: [new Intl.Locale(String(rl))];
27-
} catch {
28-
const msg = 'Unsupported value for u:locale option';
29-
const optSource = getValueSource(localeOpt);
30-
ctx.onError(new MessageResolutionError('bad-option', msg, optSource));
31-
}
32-
}
33-
3415
this.dir = undefined;
3516
const dirOpt = options?.get('u:dir');
3617
if (dirOpt) {
@@ -66,7 +47,7 @@ export class MessageFunctionContext {
6647
}
6748

6849
get locales() {
69-
return this.#locales.map(String);
50+
return this.#ctx.locales.map(String);
7051
}
7152

7253
get onError() {

mf2/messageformat/src/resolve/function-ref.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ describe('inputs with options', () => {
6262
});
6363
expect(parts).toEqual(nf.formatToParts(12345678));
6464
});
65-
66-
test('u:locale value take precedence', () => {
67-
const mf = new MessageFormat(
68-
'en',
69-
'{$val :number minimumFractionDigits=2 u:locale=ar}'
70-
);
71-
const msg = mf.formatToParts({ val: 12345 });
72-
const { parts } = msg[1] as MessageNumberPart;
73-
74-
const ar = new Intl.NumberFormat('ar', { minimumFractionDigits: 2 });
75-
expect(parts).toEqual(ar.formatToParts(12345));
76-
});
7765
});
7866

7967
describe('Type casts based on runtime', () => {

mf2/messageformat/src/resolve/resolve-function-ref.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ function resolveOptions(ctx: Context, options: Options | undefined) {
5959
const opt: Record<string, unknown> = Object.create(null);
6060
if (options) {
6161
for (const [name, value] of options) {
62-
if (name !== 'u:dir' && name !== 'u:id' && name !== 'u:locale') {
63-
opt[name] = resolveValue(ctx, value);
64-
}
62+
if (!name.startsWith('u:')) opt[name] = resolveValue(ctx, value);
6563
}
6664
}
6765
return opt;

0 commit comments

Comments
 (0)