Skip to content

Commit fda6a4b

Browse files
committed
Add file encoding option, default to latin1
1 parent 585aabc commit fda6a4b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ a browser.
3737
options: {
3838
biDiSupport: false, // enables bi-directional text support
3939
defaultLocale: 'en', // used if resolution from filename fails
40+
encoding: 'latin1', // .properties file encoding
4041
keyPath: false, // if true, dots '.' key names will result
4142
// in multi-level objects -- use a string
4243
// value to customize

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ function localeFromResourcePath (resourcePath, pathSep, defaultLocale) {
1515
return /^[a-z]{2,3}$/.test(locale || '') ? locale : defaultLocale
1616
}
1717

18-
module.exports = function (input) {
19-
const { biDiSupport, defaultLocale, keyPath, pathSep } = loaderUtils.getOptions(this)
18+
module.exports = function (content) {
19+
const { biDiSupport, defaultLocale, encoding, keyPath, pathSep } = loaderUtils.getOptions(this) || {}
20+
const input = content.toString(encoding || 'latin1')
2021
const translations = parse(input, keyPath || false)
2122
const locale = localeFromResourcePath(this.resourcePath, pathSep || '_', defaultLocale || 'en')
2223
const mf = new MessageFormat(locale)
2324
if (biDiSupport) mf.setBiDiSupport()
2425
return mf.compile(translations).toString('module.exports')
2526
}
27+
module.exports.raw = true

0 commit comments

Comments
 (0)