Skip to content

Commit bfe350e

Browse files
committed
Update to messageformat 3
1 parent 580a1f8 commit bfe350e

3 files changed

Lines changed: 51 additions & 7 deletions

File tree

index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { parse } = require('dot-properties')
22
const loaderUtils = require('loader-utils')
33
const MessageFormat = require('messageformat')
4+
const compileModule = require('messageformat/compile-module');
45
const path = require('path')
56
const uv = require('uv')
67

@@ -16,22 +17,23 @@ function localeFromResourcePath(resourcePath, pathSep, defaultLocale) {
1617
return /^[a-z]{2,3}$/.test(locale || '') ? locale : defaultLocale
1718
}
1819

19-
module.exports = function(content) {
20-
let { biDiSupport, defaultLocale, encoding, keyPath, pathSep } =
20+
module.exports = function messageformatPropertiesLoader(content) {
21+
let { defaultLocale, encoding, keyPath, pathSep, ...mfOpt } =
2122
loaderUtils.getOptions(this) || {}
2223

2324
if (!encoding || encoding === 'auto')
2425
encoding = uv(content) ? 'utf8' : 'latin1'
2526
const input = content.toString(encoding)
2627

27-
const translations = parse(input, keyPath || false)
28+
const messages = parse(input, keyPath || false)
2829
const locale = localeFromResourcePath(
2930
this.resourcePath,
3031
pathSep || '_',
3132
defaultLocale || 'en'
3233
)
33-
const mf = new MessageFormat(locale)
34-
if (biDiSupport) mf.setBiDiSupport()
35-
return mf.compile(translations).toString('module.exports')
34+
const mf = new MessageFormat(locale, mfOpt)
35+
return compileModule(mf, messages);
3636
}
37+
38+
// get content as Buffer rather than string
3739
module.exports.raw = true

package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
"uv": "^1.1.0"
2626
},
2727
"peerDependencies": {
28-
"messageformat": "1.x | 2.x"
28+
"messageformat": "^3.0.0-beta"
2929
},
3030
"prettier": {
3131
"trailingComma": "none",
3232
"semi": false,
3333
"singleQuote": true
34+
},
35+
"devDependencies": {
36+
"messageformat": "^3.0.0-beta.1"
3437
}
3538
}

0 commit comments

Comments
 (0)