@@ -1590,9 +1590,9 @@ Mundo!`;
15901590
15911591 mockFileOperations ( input ) ;
15921592
1593- const jsonLoader = createBucketLoader ( "php" , "i18n/[locale].php" ) ;
1594- jsonLoader . setDefaultLocale ( "en" ) ;
1595- const data = await jsonLoader . pull ( "en" ) ;
1593+ const phpLoader = createBucketLoader ( "php" , "i18n/[locale].php" ) ;
1594+ phpLoader . setDefaultLocale ( "en" ) ;
1595+ const data = await phpLoader . pull ( "en" ) ;
15961596
15971597 expect ( data ) . toEqual ( expectedOutput ) ;
15981598 } ) ;
@@ -1624,53 +1624,147 @@ return array(
16241624
16251625 mockFileOperations ( input ) ;
16261626
1627- const jsonLoader = createBucketLoader ( "php" , "i18n/[locale].php" ) ;
1628- jsonLoader . setDefaultLocale ( "en" ) ;
1629- await jsonLoader . pull ( "en" ) ;
1627+ const phpLoader = createBucketLoader ( "php" , "i18n/[locale].php" ) ;
1628+ phpLoader . setDefaultLocale ( "en" ) ;
1629+ await phpLoader . pull ( "en" ) ;
16301630
1631- await jsonLoader . push ( "es" , {
1631+ await phpLoader . push ( "es" , {
16321632 "button.title" : "Enviar" ,
16331633 "button.description/0" : "Hola" ,
16341634 "button.description/1" : "Adiós" ,
16351635 } ) ;
16361636
16371637 expect ( fs . writeFile ) . toHaveBeenCalledWith ( "i18n/es.php" , expectedOutput , { encoding : "utf-8" , flag : "w" } ) ;
16381638 } ) ;
1639+ } ) ;
16391640
1640- describe ( "po bucket loader" , ( ) => {
1641- it ( "should load po file" , async ( ) => {
1642- setupFileMocks ( ) ;
1641+ describe ( "po bucket loader" , ( ) => {
1642+ it ( "should load po file" , async ( ) => {
1643+ setupFileMocks ( ) ;
16431644
1644- const input = `msgid "Hello"\nmsgstr "Hello"` ;
1645- const expectedOutput = { "Hello/singular" : "Hello" } ;
1645+ const input = `msgid "Hello"\nmsgstr "Hello"` ;
1646+ const expectedOutput = { "Hello/singular" : "Hello" } ;
16461647
1647- mockFileOperations ( input ) ;
1648+ mockFileOperations ( input ) ;
1649+
1650+ const poLoader = createBucketLoader ( "po" , "i18n/[locale].po" ) ;
1651+ poLoader . setDefaultLocale ( "en" ) ;
1652+ const data = await poLoader . pull ( "en" ) ;
1653+
1654+ expect ( data ) . toEqual ( expectedOutput ) ;
1655+ } ) ;
16481656
1649- const jsonLoader = createBucketLoader ( "po" , "i18n/[locale].po" ) ;
1650- jsonLoader . setDefaultLocale ( "en" ) ;
1651- const data = await jsonLoader . pull ( "en" ) ;
1657+ it ( "should save po file" , async ( ) => {
1658+ setupFileMocks ( ) ;
16521659
1653- expect ( data ) . toEqual ( expectedOutput ) ;
1660+ const input = `msgid "Hello"\nmsgstr "Hello"` ;
1661+ const expectedOutput = `msgid "Hello"\nmsgstr "Hola"` ;
1662+
1663+ mockFileOperations ( input ) ;
1664+
1665+ const poLoader = createBucketLoader ( "po" , "i18n/[locale].po" ) ;
1666+ poLoader . setDefaultLocale ( "en" ) ;
1667+ await poLoader . pull ( "en" ) ;
1668+
1669+ await poLoader . push ( "es" , {
1670+ "Hello/singular" : "Hola" ,
16541671 } ) ;
16551672
1656- it ( "should save po file" , async ( ) => {
1657- setupFileMocks ( ) ;
1673+ expect ( fs . writeFile ) . toHaveBeenCalledWith ( "i18n/es.po" , expectedOutput , { encoding : "utf-8" , flag : "w" } ) ;
1674+ } ) ;
1675+ } ) ;
16581676
1659- const input = `msgid "Hello"\nmsgstr "Hello"` ;
1660- const expectedOutput = `msgid "Hello"\nmsgstr "Hola"` ;
1677+ describe ( "vue-json bucket loader" , ( ) => {
1678+ const template = `<template>
1679+ <div id="app">
1680+ <label for="locale">locale</label>
1681+ <select v-model="locale">
1682+ <option>en</option>
1683+ <option>ja</option>
1684+ </select>
1685+ <p>message: {{ $t('hello') }}</p>
1686+ </div>
1687+ </template>` ;
1688+ const script = `<script>
1689+ export default {
1690+ name: 'app',
1691+ data () {
1692+ this.$i18n.locale = 'en';
1693+ return { locale: 'en' }
1694+ },
1695+ watch: {
1696+ locale (val) {
1697+ this.$i18n.locale = val
1698+ }
1699+ }
1700+ }
1701+ </script>` ;
16611702
1662- mockFileOperations ( input ) ;
1703+ it ( "should load vue-json file" , async ( ) => {
1704+ setupFileMocks ( ) ;
16631705
1664- const jsonLoader = createBucketLoader ( "po" , "i18n/[locale].po" ) ;
1665- jsonLoader . setDefaultLocale ( "en" ) ;
1666- await jsonLoader . pull ( "en" ) ;
1706+ const input = `${ template }
16671707
1668- await jsonLoader . push ( "es" , {
1669- "Hello/singular" : "Hola" ,
1670- } ) ;
1708+ <i18n>
1709+ {
1710+ "en": {
1711+ "hello": "hello world!"
1712+ }
1713+ }
1714+ </i18n>
16711715
1672- expect ( fs . writeFile ) . toHaveBeenCalledWith ( "i18n/es.po" , expectedOutput , { encoding : "utf-8" , flag : "w" } ) ;
1716+ ${ script } `;
1717+ const expectedOutput = { hello : "hello world!" } ;
1718+
1719+ mockFileOperations ( input ) ;
1720+
1721+ const vueLoader = createBucketLoader ( "vue-json" , "i18n/[locale].vue" ) ;
1722+ vueLoader . setDefaultLocale ( "en" ) ;
1723+ const data = await vueLoader . pull ( "en" ) ;
1724+
1725+ expect ( data ) . toEqual ( expectedOutput ) ;
1726+ } ) ;
1727+
1728+ it ( "should save vue-json file" , async ( ) => {
1729+ setupFileMocks ( ) ;
1730+
1731+ const input = `${ template }
1732+
1733+ <i18n>
1734+ {
1735+ "en": {
1736+ "hello": "hello world!"
1737+ }
1738+ }
1739+ </i18n>
1740+
1741+ ${ script } `;
1742+ const expectedOutput = `${ template }
1743+
1744+ <i18n>
1745+ {
1746+ "en": {
1747+ "hello": "hello world!"
1748+ },
1749+ "es": {
1750+ "hello": "hola mundo!"
1751+ }
1752+ }
1753+ </i18n>
1754+
1755+ ${ script } `;
1756+
1757+ mockFileOperations ( input ) ;
1758+
1759+ const vueLoader = createBucketLoader ( "vue-json" , "i18n/App.vue" ) ;
1760+ vueLoader . setDefaultLocale ( "en" ) ;
1761+ await vueLoader . pull ( "en" ) ;
1762+
1763+ await vueLoader . push ( "es" , {
1764+ hello : "hola mundo!" ,
16731765 } ) ;
1766+
1767+ expect ( fs . writeFile ) . toHaveBeenCalledWith ( "i18n/App.vue" , expectedOutput , { encoding : "utf-8" , flag : "w" } ) ;
16741768 } ) ;
16751769 } ) ;
16761770} ) ;
0 commit comments