@@ -31,7 +31,7 @@ export default class Localization {
31
31
* DOMLocalization. In case of errors, fetch the next context in the
32
32
* fallback chain.
33
33
*
34
- * @param {Array<Array> } keys - Translation keys to format.
34
+ * @param {Array<Object> } keys - Translation keys to format.
35
35
* @param {Function } method - Formatting function.
36
36
* @returns {Promise<Array<string|Object>> }
37
37
* @private
@@ -64,8 +64,8 @@ export default class Localization {
64
64
* objects which are suitable for the translation of DOM elements.
65
65
*
66
66
* docL10n.formatMessages([
67
- * [ 'hello', { who: 'Mary' }] ,
68
- * [ 'welcome', undefined]
67
+ * {id: 'hello', args: { who: 'Mary' }} ,
68
+ * {id: 'welcome'}
69
69
* ]).then(console.log);
70
70
*
71
71
* // [
@@ -75,7 +75,7 @@ export default class Localization {
75
75
*
76
76
* Returns a Promise resolving to an array of the translation strings.
77
77
*
78
- * @param {Array<Array > } keys
78
+ * @param {Array<Object > } keys
79
79
* @returns {Promise<Array<{value: string, attributes: Object}>> }
80
80
* @private
81
81
*/
@@ -90,16 +90,16 @@ export default class Localization {
90
90
* either be simple string identifiers or `[id, args]` arrays.
91
91
*
92
92
* docL10n.formatValues([
93
- * [ 'hello', { who: 'Mary' }] ,
94
- * [ 'hello', { who: 'John' }] ,
95
- * [ 'welcome']
93
+ * {id: 'hello', args: { who: 'Mary' }} ,
94
+ * {id: 'hello', args: { who: 'John' }} ,
95
+ * {id: 'welcome'}
96
96
* ]).then(console.log);
97
97
*
98
98
* // ['Hello, Mary!', 'Hello, John!', 'Welcome!']
99
99
*
100
100
* Returns a Promise resolving to an array of the translation strings.
101
101
*
102
- * @param {Array<Array > } keys
102
+ * @param {Array<Object > } keys
103
103
* @returns {Promise<Array<string>> }
104
104
*/
105
105
formatValues ( keys ) {
@@ -129,7 +129,7 @@ export default class Localization {
129
129
* @returns {Promise<string> }
130
130
*/
131
131
async formatValue ( id , args ) {
132
- const [ val ] = await this . formatValues ( [ [ id , args ] ] ) ;
132
+ const [ val ] = await this . formatValues ( [ { id, args} ] ) ;
133
133
return val ;
134
134
}
135
135
@@ -249,17 +249,17 @@ function keysFromContext(method, ctx, keys, translations) {
249
249
const messageErrors = [ ] ;
250
250
const missingIds = new Set ( ) ;
251
251
252
- keys . forEach ( ( key , i ) => {
252
+ keys . forEach ( ( { id , args } , i ) => {
253
253
if ( translations [ i ] !== undefined ) {
254
254
return ;
255
255
}
256
256
257
- if ( ctx . hasMessage ( key [ 0 ] ) ) {
257
+ if ( ctx . hasMessage ( id ) ) {
258
258
messageErrors . length = 0 ;
259
- translations [ i ] = method ( ctx , messageErrors , key [ 0 ] , key [ 1 ] ) ;
259
+ translations [ i ] = method ( ctx , messageErrors , id , args ) ;
260
260
// XXX: Report resolver errors
261
261
} else {
262
- missingIds . add ( key [ 0 ] ) ;
262
+ missingIds . add ( id ) ;
263
263
}
264
264
} ) ;
265
265
0 commit comments