11const { parse } = require ( 'dot-properties' )
22const loaderUtils = require ( 'loader-utils' )
33const MessageFormat = require ( 'messageformat' )
4+ const compileModule = require ( 'messageformat/compile-module' ) ;
45const path = require ( 'path' )
56const 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
3739module . exports . raw = true
0 commit comments