From 8ad1b8c73205a89edf1adbd61f7ba2c34a120f4f Mon Sep 17 00:00:00 2001 From: * <*> Date: Fri, 1 Sep 2023 09:08:30 +0800 Subject: [PATCH] Match-id-39198bccbc0c095f33c70cefebfc758ebe67228f --- packages/horizon-intl/.eslintrc.js | 74 +++++ packages/horizon-intl/.prettierrc.js | 15 + packages/horizon-intl/README.md | 2 + packages/horizon-intl/babel.config.js | 26 ++ packages/horizon-intl/example/App.tsx | 45 +++ .../example/components/Example1.tsx | 19 ++ .../example/components/Example2.tsx | 19 ++ .../example/components/Example3.tsx | 25 ++ .../example/components/Example4.tsx | 21 ++ .../example/components/Example5.tsx | 24 ++ .../example/components/Example6.tsx | 26 ++ .../example/components/Example6Child.tsx | 19 ++ packages/horizon-intl/example/index.html | 102 +++++++ packages/horizon-intl/example/index.tsx | 15 + packages/horizon-intl/example/locale/en.ts | 11 + packages/horizon-intl/example/locale/zh.ts | 10 + packages/horizon-intl/index.ts | 45 +++ packages/horizon-intl/jest.config.js | 24 ++ packages/horizon-intl/package.json | 63 ++++ packages/horizon-intl/rollup.config.js | 51 ++++ packages/horizon-intl/src/constants/index.ts | 68 +++++ packages/horizon-intl/src/core/I18n.ts | 127 +++++++++ .../src/core/components/FormattedMessage.tsx | 43 +++ .../src/core/components/I18nProvider.tsx | 52 ++++ .../src/core/components/InjectI18n.tsx | 53 ++++ packages/horizon-intl/src/core/createI18n.ts | 20 ++ .../horizon-intl/src/core/hook/useI18n.ts | 25 ++ .../horizon-intl/src/format/Translation.ts | 101 +++++++ .../horizon-intl/src/format/cache/cache.ts | 20 ++ .../src/format/fomatters/DateTimeFormatter.ts | 56 ++++ .../src/format/fomatters/NumberFormatter.ts | 44 +++ .../src/format/fomatters/PluralFormatter.ts | 53 ++++ .../src/format/fomatters/SelectFormatter.ts | 39 +++ .../src/format/generateFormatters.ts | 84 ++++++ .../src/format/getFormatMessage.ts | 53 ++++ packages/horizon-intl/src/parser/Lexer.ts | 189 ++++++++++++ .../horizon-intl/src/parser/mappingRule.ts | 63 ++++ .../src/parser/parseMappingRule.ts | 230 +++++++++++++++ packages/horizon-intl/src/parser/parser.ts | 197 +++++++++++++ packages/horizon-intl/src/types/interfaces.ts | 192 +++++++++++++ packages/horizon-intl/src/types/types.ts | 51 ++++ .../horizon-intl/src/utils/copyStaticProps.ts | 77 +++++ .../horizon-intl/src/utils/eventListener.ts | 69 +++++ .../horizon-intl/src/utils/getTokenAST.ts | 42 +++ .../horizon-intl/src/utils/parseRuleUtils.ts | 207 ++++++++++++++ packages/horizon-intl/src/utils/utils.ts | 37 +++ packages/horizon-intl/tests/core/I18n.test.ts | 125 ++++++++ .../core/components/FormattedMessage.test.tsx | 52 ++++ .../core/components/I18nProvider.test.tsx | 90 ++++++ .../tests/core/components/InjectI18n.test.tsx | 47 +++ .../horizon-intl/tests/core/creatI18n.test.ts | 35 +++ .../tests/core/hooks/useIntl.test.tsx | 67 +++++ .../tests/format/Translation.test.ts | 116 ++++++++ .../tests/format/cache/cache.test.ts | 19 ++ .../horizon-intl/tests/format/compile.test.ts | 57 ++++ .../formatters/DateTimeFormatter.test.ts | 89 ++++++ .../format/formatters/NumberFormatter.test.ts | 88 ++++++ .../tests/format/getFormatMessage.test.ts | 38 +++ packages/horizon-intl/tests/index.test.ts | 38 +++ .../tests/parser/checkSelectType.test.ts | 18 ++ .../tests/parser/checkStateGroup.test.ts | 36 +++ .../tests/utils/copyStatics.test.ts | 67 +++++ .../tests/utils/eventListener.test.ts | 49 ++++ .../tests/utils/generateKey.test.ts | 36 +++ .../tests/utils/getTokenAST.test.ts | 162 +++++++++++ .../tests/utils/ruleUtils.test.ts | 269 ++++++++++++++++++ packages/horizon-intl/tsconfig.json | 71 +++++ packages/horizon-intl/webpack.config.js | 52 ++++ 68 files changed, 4449 insertions(+) create mode 100644 packages/horizon-intl/.eslintrc.js create mode 100644 packages/horizon-intl/.prettierrc.js create mode 100644 packages/horizon-intl/README.md create mode 100644 packages/horizon-intl/babel.config.js create mode 100644 packages/horizon-intl/example/App.tsx create mode 100644 packages/horizon-intl/example/components/Example1.tsx create mode 100644 packages/horizon-intl/example/components/Example2.tsx create mode 100644 packages/horizon-intl/example/components/Example3.tsx create mode 100644 packages/horizon-intl/example/components/Example4.tsx create mode 100644 packages/horizon-intl/example/components/Example5.tsx create mode 100644 packages/horizon-intl/example/components/Example6.tsx create mode 100644 packages/horizon-intl/example/components/Example6Child.tsx create mode 100644 packages/horizon-intl/example/index.html create mode 100644 packages/horizon-intl/example/index.tsx create mode 100644 packages/horizon-intl/example/locale/en.ts create mode 100644 packages/horizon-intl/example/locale/zh.ts create mode 100644 packages/horizon-intl/index.ts create mode 100644 packages/horizon-intl/jest.config.js create mode 100644 packages/horizon-intl/package.json create mode 100644 packages/horizon-intl/rollup.config.js create mode 100644 packages/horizon-intl/src/constants/index.ts create mode 100644 packages/horizon-intl/src/core/I18n.ts create mode 100644 packages/horizon-intl/src/core/components/FormattedMessage.tsx create mode 100644 packages/horizon-intl/src/core/components/I18nProvider.tsx create mode 100644 packages/horizon-intl/src/core/components/InjectI18n.tsx create mode 100644 packages/horizon-intl/src/core/createI18n.ts create mode 100644 packages/horizon-intl/src/core/hook/useI18n.ts create mode 100644 packages/horizon-intl/src/format/Translation.ts create mode 100644 packages/horizon-intl/src/format/cache/cache.ts create mode 100644 packages/horizon-intl/src/format/fomatters/DateTimeFormatter.ts create mode 100644 packages/horizon-intl/src/format/fomatters/NumberFormatter.ts create mode 100644 packages/horizon-intl/src/format/fomatters/PluralFormatter.ts create mode 100644 packages/horizon-intl/src/format/fomatters/SelectFormatter.ts create mode 100644 packages/horizon-intl/src/format/generateFormatters.ts create mode 100644 packages/horizon-intl/src/format/getFormatMessage.ts create mode 100644 packages/horizon-intl/src/parser/Lexer.ts create mode 100644 packages/horizon-intl/src/parser/mappingRule.ts create mode 100644 packages/horizon-intl/src/parser/parseMappingRule.ts create mode 100644 packages/horizon-intl/src/parser/parser.ts create mode 100644 packages/horizon-intl/src/types/interfaces.ts create mode 100644 packages/horizon-intl/src/types/types.ts create mode 100644 packages/horizon-intl/src/utils/copyStaticProps.ts create mode 100644 packages/horizon-intl/src/utils/eventListener.ts create mode 100644 packages/horizon-intl/src/utils/getTokenAST.ts create mode 100644 packages/horizon-intl/src/utils/parseRuleUtils.ts create mode 100644 packages/horizon-intl/src/utils/utils.ts create mode 100644 packages/horizon-intl/tests/core/I18n.test.ts create mode 100644 packages/horizon-intl/tests/core/components/FormattedMessage.test.tsx create mode 100644 packages/horizon-intl/tests/core/components/I18nProvider.test.tsx create mode 100644 packages/horizon-intl/tests/core/components/InjectI18n.test.tsx create mode 100644 packages/horizon-intl/tests/core/creatI18n.test.ts create mode 100644 packages/horizon-intl/tests/core/hooks/useIntl.test.tsx create mode 100644 packages/horizon-intl/tests/format/Translation.test.ts create mode 100644 packages/horizon-intl/tests/format/cache/cache.test.ts create mode 100644 packages/horizon-intl/tests/format/compile.test.ts create mode 100644 packages/horizon-intl/tests/format/formatters/DateTimeFormatter.test.ts create mode 100644 packages/horizon-intl/tests/format/formatters/NumberFormatter.test.ts create mode 100644 packages/horizon-intl/tests/format/getFormatMessage.test.ts create mode 100644 packages/horizon-intl/tests/index.test.ts create mode 100644 packages/horizon-intl/tests/parser/checkSelectType.test.ts create mode 100644 packages/horizon-intl/tests/parser/checkStateGroup.test.ts create mode 100644 packages/horizon-intl/tests/utils/copyStatics.test.ts create mode 100644 packages/horizon-intl/tests/utils/eventListener.test.ts create mode 100644 packages/horizon-intl/tests/utils/generateKey.test.ts create mode 100644 packages/horizon-intl/tests/utils/getTokenAST.test.ts create mode 100644 packages/horizon-intl/tests/utils/ruleUtils.test.ts create mode 100644 packages/horizon-intl/tsconfig.json create mode 100644 packages/horizon-intl/webpack.config.js diff --git a/packages/horizon-intl/.eslintrc.js b/packages/horizon-intl/.eslintrc.js new file mode 100644 index 00000000..3ca73b64 --- /dev/null +++ b/packages/horizon-intl/.eslintrc.js @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * openGauss is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +module.exports = { + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'prettier', + ], + root: true, + + plugins: ['jest', 'no-for-of-loops', 'no-function-declare-after-return', 'react', '@typescript-eslint'], + + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 8, + sourceType: 'module', + ecmaFeatures: { + jsx: true, + modules: true, + experimentalObjectRestSpread: true, + }, + }, + env: { + browser: true, + jest: true, + node: true, + es6: true, + }, + rules: { + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-empty-function': 'off', + semi: ['warn', 'always'], + quotes: ['warn', 'single'], + 'accessor-pairs': 'off', + 'brace-style': ['error', '1tbs'], + 'func-style': ['warn', 'declaration', { allowArrowFunctions: true }], + 'max-lines-per-function': 'off', + 'object-curly-newline': 'off', + // 尾随逗号 + 'comma-dangle': ['error', 'only-multiline'], + + 'no-constant-condition': 'off', + 'no-for-of-loops/no-for-of-loops': 'error', + 'no-function-declare-after-return/no-function-declare-after-return': 'error', + }, + globals: { + isDev: true, + isTest: true, + }, + overrides: [ + { + files: ['scripts/tests/**/*.js'], + globals: { + container: true, + }, + }, + ], +}; diff --git a/packages/horizon-intl/.prettierrc.js b/packages/horizon-intl/.prettierrc.js new file mode 100644 index 00000000..4bf32557 --- /dev/null +++ b/packages/horizon-intl/.prettierrc.js @@ -0,0 +1,15 @@ +module.exports = { + printWidth: 120, // 一行120字符数,如果超过会进行换行 + tabWidth: 2, // tab等2个空格 + useTabs: false, // 用空格缩进行 + semi: true, // 行尾使用分号 + singleQuote: true, // 字符串使用单引号 + quoteProps: 'as-needed', // 仅在需要时在对象属性添加引号 + jsxSingleQuote: false, // 在JSX中使用双引号 + trailingComma: 'es5', // 使用尾逗号(对象、数组等) + bracketSpacing: true, // 对象的括号间增加空格 + bracketSameLine: false, // 将多行JSX元素的>放在最后一行的末尾 + arrowParens: 'avoid', // 在唯一的arrow函数参数周围省略括号 + vueIndentScriptAndStyle: false, // 不缩进Vue文件中的