lang-to-json

0.0.7 • Public • Published

安装lang-to-json:(全局安装!)

  • npm install lang-to-json -g

参数:

参数名 必选 类型 说明
-x string excel路径
-o string 输出路径

使用示例

  // 只使用 -x 参数,指明excel文件路径名。可相对路径亦可绝对。
  D:\raojianbing\anpm\lang-to-json>lang-to-json -x test/excel.xlsx
  ----
  // 使用 -x 参数,指明excel文件路径名。-o 指明输出的json语言包路径。
  D:\raojianbing\anpm\lang-to-json>lang-to-json -x test/excel.xlsx -o ../lang
  

excel示例,filename字段用来生成文件名(为了兼容,lang字段也可以生成文件名,优先filename。生成.json格式)

生成的en_lang.json文件如下

{
    "filename": "en_lang",
    "lang": "en",
    "title_image": "body_ \"dsa\" en_m.png",
    "apply_btn": "Apply d'd'now",
    "apply_condition_t": "recruitment conditions",
    "apply_condition_c": [
        {
            "c": "1,condition condition condition condition, condition condition condition condition. Condition condition condition, condition condition condition."
        },
        {
            "c": "2,condition condition condition condition, condition condition condition condition. Condition condition condition, condition condition condition."
        }
    ],
    "test": [
        "test",
        "test2"
    ]
}

基于 https://github.com/stevetarver/excel-as-json

如果想通过 apply_reward_c[0], apply_reward_c[1] 这种方式添加基本类型,需要做如下修改。

因为excel-as-json的作者不赞同数组的基础相是基本类型。 找到文件,一般node安装没有改过目录则 C:\Users\DW\AppData\Roaming\npm\node_modules\lang-to-json\node_modules\excel-as-json\lib\excel-as-json.js 文件

   if (keyIsList && (index != null)) {
        console.error("WARNING: Unexpected key path terminal containing an indexed list for <" + keyName + ">");
        console.error("WARNING: Indexed arrays indicate a list of objects and should not be the last element in a key path");
        console.error("WARNING: The last element of a key path should be a key name or flat array. E.g. alias, aliases[]");
        console.error("TIPS: 以下内容为私自扩展,支持arr[0],arr[1]类似写法,追加基本类型数据")
        if (index == 0) {
              obj[keyName] = []
        }
        return obj[keyName][index] = convertValue(value)
    console.error("TIPS: 以上内容为私自扩展,支持arr[0],arr[1]类似写法,追加基本类型数据")
   }

Readme

Keywords

none

Package Sidebar

Install

npm i lang-to-json

Weekly Downloads

0

Version

0.0.7

License

ISC

Unpacked Size

4.49 kB

Total Files

4

Last publish

Collaborators

  • diyao