{"_id":"@aligov/global-string-format","_rev":"8-9a3fd642e16551352a6e617ea49df074","name":"@aligov/global-string-format","description":"@aligov/global-string-format 提供普通文案国际化能力，业务方传入数据字典，组件返回id对应的文案。","dist-tags":{"latest":"1.0.7"},"versions":{"1.0.7":{"name":"@aligov/global-string-format","version":"1.0.7","author":{"name":"manxia.pc"},"license":"ISC","_id":"@aligov/global-string-format@1.0.7","maintainers":[{"name":"shenyu.wsy","email":"shenyu.wsy@alibaba-inc.com"},{"name":"liunian","email":"dengjij@gmail.com"},{"name":"tao1991123","email":"tao360907796@gmail.com"},{"name":"itrip","email":"1198488651@qq.com"},{"name":"xiazhiqiang","email":"xiazhiqiangcuc@126.com"},{"name":"zhousufa","email":"zhousufa@gmail.com"},{"name":"mo.zhou","email":"bjfuzm@163.com"},{"name":"guoliang.hgl","email":"guoliang.hgl@alibaba-inc.com"},{"name":"zwhu","email":"zwhu2014@foxmail.com"},{"name":"daip","email":"15858208586@163.com"},{"name":"baizhao","email":"ethan.cqw@alibaba-inc.com"}],"homepage":"http://gitlab.alibaba-inc.com/parrot/global-string-format","bugs":{"url":"http://gitlab.alibaba-inc.com/parrot/global-string-format/issues"},"dist":{"shasum":"6e2d5ebf0b6164b155a75d882c6f86ebb10a301f","tarball":"https://registry.npmjs.org/@aligov/global-string-format/-/global-string-format-1.0.7.tgz","fileCount":15,"integrity":"sha512-6gWz+DZI+QXj6hcsplGkAe6eZZvgVQq5mjJMnUb8AKBJzwcAfWGjb7NuuhgQoI13YGPBA/HG17eAM2bEVr+y0g==","signatures":[{"sig":"MEQCIDRq9mhI7ePuLyoIckS50kuSSW+B119SgZfRm/FlBRfIAiBloNSr7IfxLPYKRiqa62VhdRQGTksd5WMCJ5inyVlhYw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":58638,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzEltCRA9TVsSAnZWagAANAgP/1k6CzgFQW8Xzd/cn89Q\nnI48BeDxh5Hdw837Dxc2yAkW0NPYj2PaSSuR8R8CGj7i9tQvByO9SOVne/s8\nToaqNX6lxa6zh0zyZ+nodXC/RGY4xyFYWVdU7pHxh1201QtsQE2lr/28qaqb\nGCMfPat6SRbIFW3d/IyVa3pZYWkn4bwsB7ARpeUL4+B4SnOn+zo+Xi8pq1OS\nvCSn1azjBVBwPhXnA3NPGmFvm+JXElor6oR18HVmArYit4aoUCVPrj7jzPug\ndUZdhBoUdIte/KVZO54ExRiSG1EieAW77er2fHPtwMh49Nc1zAvdEfguHTSN\ngVSKrtyD2HrtRQctd4IkF+XLvMvyD1r+KYfHcW/pwF5M771U2IMS1oeAzDHg\nyo48IwFaFJMLdHJXn+36taM/CMMQyPHtN3oixLXPydIN6TgivJQ74xsswXnu\ngupOuUS9GcG63hZFMSgZZFgAqhEsWtEExmf5d8/QlaE4z1oBNChMUiigx6u8\nGhWy69JmERFAjba+OY/y064CH4eHpNjILbPmJYcsQ0IDqjEjFeNnMuWSTyJP\nJiYsoT15g8HZFoo7xyzCtbtPF35p8clHUl75vuR7mCz6SrE1ECBeSMqBjUbl\nuduM/hmBcJBfMYWmYqwOTB2DlqBLgXsRU7WjSqPbjdiD3XRXHGE0wrZE+Ujq\nd0D2\r\n=GvFk\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/index.js","_from":"@aligov/global-string-format@1.0.7","scripts":{"test":"mocha","build":"npm run build:types && npm run build:js","start":"concurrently npm:build:types:watch npm:build:js:watch","eslint":"git diff-index --name-only HEAD | grep -E \"(.*\\/)?src\\/(.*)\\.(jsx|js|ts|tsx)$\" | xargs node_modules/eslint/bin/eslint.js -c .eslintrc.js","webpack":"concurrently npm:build:types:watch npm:build:js:watch \"node_modules/.bin/webpack-dev-server --config example/react-element/webpack.js\"","build:js":"babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps ","type-check":"tsc --noEmit","build:types":"tsc --emitDeclarationOnly","build:js:watch":"babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps --watch","type-check:watch":"npm run type-check -- --watch","build:types:watch":"tsc --emitDeclarationOnly -w"},"_npmUser":{"name":"baizhao","email":"ethan.cqw@alibaba-inc.com"},"_resolved":"https://registry.npm.alibaba-inc.com/@aligov/global-string-format/download/@aligov/global-string-format-1.0.7.tgz","pre-commit":["eslint"],"repository":{"url":"git@gitlab.alibaba-inc.com:parrot/global-string-format.git","type":"git"},"_npmVersion":"6.13.4","description":"@aligov/global-string-format 提供普通文案国际化能力，业务方传入数据字典，组件返回id对应的文案。","directories":{},"_nodeVersion":"12.13.0","browserslist":"ie 10","dependencies":{"universal-env":"^1.0.1","intl-messageformat":"^2.2.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"^4.2.0","find":"^0.3.0","mocha":"^6.1.4","eslint":"^5.16.0","expect":"^24.8.0","webpack":"^4.35.2","electron":"^5.0.1","minimist":"^1.2.0","@babel/cli":"^7.4.4","pre-commit":"^1.2.2","typescript":"^3.4.5","@babel/core":"^7.4.5","@types/node":"^11.13.8","http-server":"^0.11.1","webpack-cli":"^3.3.5","babel-eslint":"^10.0.1","babel-loader":"^8.0.6","concurrently":"^4.1.0","mocha-loader":"^2.0.1","power-assert":"^1.6.1","eslint-tinker":"^0.5.0","core-js-compat":"^3.0.1","@babel/preset-env":"^7.4.5","eslint-plugin-jest":"^22.5.1","webpack-dev-server":"^3.7.2","@babel/preset-react":"^7.0.0","eslint-plugin-babel":"^5.3.0","eslint-plugin-react":"^7.13.0","html-webpack-plugin":"^3.2.0","eslint-config-airbnb":"^17.1.0","eslint-plugin-import":"^2.17.2","eslint-config-prettier":"^4.2.0","eslint-plugin-jsx-a11y":"^6.2.1","eslint-plugin-markdown":"^1.0.0","@babel/preset-typescript":"^7.3.3","@typescript-eslint/parser":"^2.1.0","@typescript-eslint/eslint-plugin":"^2.1.0","@babel/plugin-proposal-class-properties":"^7.4.4","@babel/plugin-proposal-object-rest-spread":"^7.4.4"},"__npminstall_done":true,"_npmOperationalInternal":{"tmp":"tmp/global-string-format_1.0.7_1635998851977_0.9349945967309263","host":"s3://npm-registry-packages"}}},"time":{"created":"2021-11-04T04:07:31.913Z","modified":"2024-07-04T09:18:53.839Z","1.0.7":"2021-11-04T04:07:32.138Z"},"maintainers":[{"email":"wanyi.css@alibaba-inc.com","name":"wanyi.css"},{"email":"17682318001@163.com","name":"jasoncapricorn"},{"email":"chris_jun@aliyun.com","name":"qingkaili"},{"email":"hgxjyh@163.com","name":"huguoxin"},{"email":"shenyu.wsy@alibaba-inc.com","name":"shenyu.wsy"},{"email":"dengjij@gmail.com","name":"liunian"},{"email":"tao360907796@gmail.com","name":"tao1991123"},{"email":"1198488651@qq.com","name":"itrip"},{"email":"xiazhiqiangcuc@126.com","name":"xiazhiqiang"},{"email":"bjfuzm@163.com","name":"mo.zhou"},{"email":"guoliang.hgl@alibaba-inc.com","name":"guoliang.hgl"},{"email":"15858208586@163.com","name":"daip"},{"email":"ethan.cqw@gmail.com","name":"baizhao"}],"author":{"name":"manxia.pc"},"repository":{"url":"git@gitlab.alibaba-inc.com:parrot/global-string-format.git","type":"git"},"license":"ISC","homepage":"http://gitlab.alibaba-inc.com/parrot/global-string-format","bugs":{"url":"http://gitlab.alibaba-inc.com/parrot/global-string-format/issues"},"readme":"## @aligov/global-string-format\n@aligov/global-string-format 提供普通文案国际化能力，业务方传入数据字典，组件返回id对应的文案。\n\n### 主要特征\n- 提供获取普通文案的国际化能力\n- 可以在浏览器和node环境中运行\n- 基于国际化[多语言标准](https://yuque.antfin-inc.com/ioc-1/specification/bvyc20)\n- 支持 react/rax 对象作为变量\n- 同时支持 index 和 name 作为变量索引\n- 结合使用 [babel-plugin-string-format](http://gitlab.alibaba-inc.com/parrot/babel-plugin-string-format) 可以解决依赖组件的文案收集和透传的问题\n\n### 安装 \n \n```\ntnpm install @aligov/global-string-format --save\n```\n### 使用\n\n#### 基本使用\n\n```js\n// src/index.js\n\nimport  stringFormat from '@aligov/global-string-format';\n\n// 初始化一个实例,并将这个实例挂载到全局变量(window/global)上. 在一些通用组件可以直接用这个实例进行格式化.\nstringFormat.init('en-US', {\n  'en-US': {\n    'no_variable': 'I have noe messages',\n    'variable_test_for_index': 'I have {0} messages',\n    'variable_test_for_name': 'I have {count} messages',\n  },\n  'zh-CN': {\n    'no_variable': '我没有消息',\n    'variable_test_for_index': '我有 {0} 条消息',\n    'variable_test_for_name': '我有 {count} 条消息',\n  }\n});\n\n// 输出多语言\nstringFormat.format({\n  id: 'no_variable',\n  defaultString: 'I have noe messages'\n});\n// 输出\n// I have noe messages\n\n// 使用 index  作为变量的索引\nstringFormat.format({\n  id: 'variable_test_for_index',\n  defaultString: 'I have {0} messages'\n\n},[2])\n\n// 输出\n// I have 2 messages\n\n\n// 使用 name 作为变量的缩影\nstringFormat.format({\n  id: 'variable_test_for_name',\n  defaultString: 'I have {count} messages'\n},{count: 1})\n\n// 输出\n// I have 2 messages\n\n```\n在其他的页面或者依赖组件中, 直接调用 `stringFormat.Format` , 使用首次初始化的实例进行格式化.\n\n```js\n// src/component/other/index.js\nimport  stringFormat from '@aligov/global-string-format';\n// 使用全局共享的实例进行多语言格式化\nstringFormat.format({\n  id: 'no_variable',\n  defaultString: 'I have noe messages'\n});\n// 输出\n// I have noe messages\n\n```\n\n#### React Dom 作为变量\n\n```js\nimport  from 'react';\nimport  stringFormat from '@aligov/global-string-format';\nconst messageCountSpan = (<span style={{color: 'red'}}>2</span>);\nstringFormat.format({\n  id: 'variable_test_for_index',\n  defaultString: 'I have {0} messages'\n},[messageCountSpan],{\n  React // 注意: 需要将 React 作为参数传入\n})\n```\n\n\n### 其他的API\n\n#### 使用 StringFormat 对象\n1.StringFormat：使用 StringFormat 实例化。\n2.format：使用StringFormat实例的format方法，返回每条id对应的文案。\n\n```js\nimport  sf from '@aligov/global-string-format';\n/**\n *  @param locale Languages that need to be localized\n *  @param strings Data dictionary, ICU grammar\n */\nconst stringFormat = new sf.StringFormat('zh-CN', {\n  'en-US': {\n    'hello_world': 'hello world'\n  },\n  'zh-CN': {\n    'hello_world': '你好，国际化'\n  } \n});\n\n// 获取传入的 strings \nstringFormat.getStrings()\n\n// 进行格式化\nstringFormat.format({\n  id: 'hello_world',\n  defaultString: 'hello world'\n});\n\n```","readmeFilename":"readme.md"}