-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Add zh-CN.json translations and respective compatibility checks via i18n tools
#30378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
azasypkin
merged 5 commits into
elastic:master
from
azasypkin:issue-xxx-improve-i18n-integrate
Feb 11, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b3b779d
Add zh-CN.json translations. Improve i18n tools to do a proper transl…
azasypkin 0af7e57
Fix small typo from the old days.
azasypkin d684977
Handle review feedback.
azasypkin d50d08f
Merge branch 'master' into issue-xxx-improve-i18n-integrate
azasypkin efc4036
Remove more translations that become unused recently.
azasypkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { resolve } from 'path'; | ||
|
|
||
| // @ts-ignore | ||
| import { normalizePath, readFileAsync } from '.'; | ||
| // @ts-ignore | ||
| import rootConfig from '../../../.i18nrc.json'; | ||
|
|
||
| export interface I18nConfig { | ||
| paths: Record<string, string>; | ||
| exclude: string[]; | ||
| translations: string[]; | ||
| } | ||
|
|
||
| /** | ||
| * Merges root .i18nrc.json config with any other additional configs (e.g. from | ||
| * third-party plugins). | ||
| * @param configPaths List of config paths. | ||
| */ | ||
| export async function mergeConfigs(configPaths: string | string[] = []) { | ||
| const mergedConfig: I18nConfig = { exclude: [], translations: [], ...rootConfig }; | ||
|
|
||
| for (const configPath of Array.isArray(configPaths) ? configPaths : [configPaths]) { | ||
| const additionalConfig: I18nConfig = { | ||
| paths: {}, | ||
| exclude: [], | ||
| translations: [], | ||
| ...JSON.parse(await readFileAsync(resolve(configPath))), | ||
| }; | ||
|
|
||
| for (const [namespace, path] of Object.entries(additionalConfig.paths)) { | ||
| mergedConfig.paths[namespace] = normalizePath(resolve(configPath, '..', path)); | ||
| } | ||
|
|
||
| for (const exclude of additionalConfig.exclude) { | ||
| mergedConfig.exclude.push(normalizePath(resolve(configPath, '..', exclude))); | ||
| } | ||
|
|
||
| for (const translations of additionalConfig.translations) { | ||
| mergedConfig.translations.push(normalizePath(resolve(configPath, '..', translations))); | ||
| } | ||
| } | ||
|
|
||
| return mergedConfig; | ||
| } | ||
|
|
||
| /** | ||
| * Filters out custom paths based on the paths defined in config and that are | ||
| * known to contain i18n strings. | ||
| * @param inputPaths List of paths to filter. | ||
| * @param config I18n config instance. | ||
| */ | ||
| export function filterConfigPaths(inputPaths: string[], config: I18nConfig) { | ||
| const availablePaths = Object.values(config.paths); | ||
| const pathsForExtraction = new Set(); | ||
|
|
||
| for (const inputPath of inputPaths) { | ||
| const normalizedPath = normalizePath(inputPath); | ||
|
|
||
| // If input path is the sub path of or equal to any available path, include it. | ||
| if ( | ||
| availablePaths.some(path => normalizedPath.startsWith(`${path}/`) || path === normalizedPath) | ||
| ) { | ||
| pathsForExtraction.add(normalizedPath); | ||
| } else { | ||
| // Otherwise go through all available paths and see if any of them is the sub | ||
| // path of the input path (empty normalized path corresponds to root or above). | ||
| availablePaths | ||
| .filter(path => !normalizedPath || path.startsWith(`${normalizedPath}/`)) | ||
| .forEach(ePath => pathsForExtraction.add(ePath)); | ||
| } | ||
| } | ||
|
|
||
| return [...pathsForExtraction]; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: we need to track these files somewhere for a compatibility checks and automatic fixes.