@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33 return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
44} ;
55Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
6+ const path_1 = __importDefault ( require ( "path" ) ) ;
7+ const fs_1 = __importDefault ( require ( "fs" ) ) ;
68const json5_1 = __importDefault ( require ( "json5" ) ) ;
79const js_yaml_1 = __importDefault ( require ( "js-yaml" ) ) ;
810const debug_1 = require ( "debug" ) ;
@@ -11,12 +13,14 @@ exports.VUE_OPTIONS = '__vue__options__';
1113exports . VUE_I18N_OPTION = '__i18n' ;
1214const defaultLang = 'json' ;
1315const debug = debug_1 . debug ( 'vue-i18n-jest' ) ;
14- function generate ( blocks ) {
16+ function generate ( blocks , sourcePath ) {
1517 const base = `${ exports . VUE_OPTIONS } .${ exports . VUE_I18N_OPTION } = []` ;
1618 const codes = blocks . map ( block => {
1719 if ( block . type === 'i18n' ) {
1820 const lang = ( block . attrs && block . attrs . lang ) || defaultLang ;
19- // const lang = block.attrs?lang ?? defaultLang
21+ block . content = ( block . attrs && block . attrs . src )
22+ ? fs_1 . default . readFileSync ( getAbsolutePath ( block , sourcePath ) ) . toString ( )
23+ : block . content ;
2024 const data = convert ( block . content , lang ) ;
2125 const value = JSON . stringify ( JSON . parse ( data ) )
2226 . replace ( / \u2028 / g, '\\u2028' )
@@ -44,3 +48,8 @@ function convert(source, lang) {
4448 return source ;
4549 }
4650}
51+ function getAbsolutePath ( block , sourcePath ) {
52+ if ( path_1 . default . isAbsolute ( block . attrs . src ) )
53+ return block . attrs . src ;
54+ return path_1 . default . join ( path_1 . default . dirname ( sourcePath ) , block . attrs . src ) ;
55+ }
0 commit comments