8000 GitHub - sh-ran/i18n-check: Check i18n/L10n keys and values
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sh-ran/i18n-check

 
 

Repository files navigation

i18n check logo

rtd ci_backend issues python pypi pypistatus license coc matrix

Check i18n/L10n keys and values

i18n-check is a Python package to automate the validation of keys and values of your internationalization and localization processes.

Developed by the activist community, this process is meant to assure that development and i18n/L10n teams are in sync when using JSON based localization processes. The action can be expanded later to work for other file type processes as needed.

Contents

Conventions

activist i18n keys follow the following conventions that are enforced by i18n-check:

  • All key base paths should be the file path where the key is used prepended with i18n.
    • Starting i18n keys with a common identifier allows them to be found within checks
  • If a key is used in more than one file, then the lowest common directory followed by _global is the base path
  • Base paths should be followed by a minimally descriptive content reference
    • Only the formatting of these content references is checked via i18n-check
  • Separate base directory paths by periods (.)
  • Separate all directory and file name components as well as content references by underscores (_)
  • Repeat words in file paths for sub directory organization should not be repeated in the key

Note

An example valid key is:

File: components/component/ComponentName.ext

Key: "components.component_name.CONTENT_REFERENCE"

How it works

Commands

The following are example commands for i18n-check:

i18n-check -h  # view the help
i18n-check -gtf  # generate a test frontends to see how it works
i18n-check -a  # run all checks
# Available IDs are ki, ik, uk, nsk, rk, rv and nk (see below).
i18n-check -CHECK_ID  # run a specific check

Arguments

You provide i18n-check with the following arguments:

  • src-dir: The path to the directory that has source code to check
  • i18n-dir: The directory path to your i18n files
  • i18n-src: The name of the i18n source file

Checks

From there the following checks are ran across your codebase:

  • key-identifiers (ki): Does the source file have keys that don't match the above format or name conventions?
    • Rename them so i18n key usage is consistent and their scope is communicated in their name.
  • invalid-keys (ik): Does the codebase include i18n keys that are not within the source file?
    • Check their validity and resolve if they should be added to the i18n files or replaced.
  • unused-keys (uk): Does the source file have keys that are not used in the codebase?
    • Remove them so the localization team isn't working on strings that aren't used.
  • non-source-keys (nsk): Do the target locale files have keys that are not in the source file?
    • Remove them as they won't be used in the application.
  • repeat-keys (rk): Do any of localization files have repeat keys?
    • Separate them so that the values are not mixed when they're in production.
  • repeat-values (rv): Does the source file have repeat values that can be combined into a single key?
    • Combine them so the localization team only needs to localize one of them.
  • nested-keys (nk): Do the i18n files contain nested JSON structures?
    • Flatten them to make replacing invalid keys easier and with find-and-replace.

Each of the above checks is ran in parallel with directions for how to fix the i18n files being provided when errors are raised. Checks can also be disabled in the workflow via options passed in the configuration YAML file.

Configuration

The following details the .18n-check.yaml configuration file, with a further example being the configuration file for this repository that we use in testing.

src-dir: frontend
i18n-dir: frontend/i18n
i18n-src: frontend/i18n/en.json

checks:
  - key-identifiers: true
  - invalid-keys: true
  - unused-keys: true
  - non-source-keys: true
  - repeat-keys: true
  - repeat-values: true
  - nested-keys: true

file-types-to-check: [.ts, .js]
directories-to-skip: [frontend/node_modules]
files-to-skip: []

Common additional arguments for using specific web frameworks can be found in the dropdowns below:

Vue.js

file_types_to_check: [.vue]
directories_to_skip: [.nuxt, .output, dist]

Contributing

Public Matrix Chat

activist uses Matrix for internal communication. You're more than welcome to join us in our public chat rooms to share ideas, ask questions or just say hi to the team :)

Please see the contribution guidelines if you are interested in contributing. Work that is in progress or could be implemented is tracked in the issues and projects.

Note

Just because an issue is assigned on GitHub doesn't mean the team isn't open to your contribution! Feel free to write in the issues and we can potentially reassign it to you.

Also check the -next release- and -priority- labels in the issues for those that are most important, as well as those marked good first issue that are tailored for first-time contributors. For those new to coding or our tech stack, we've collected links to helpful documentation pages in the contribution guidelines.

We would be happy to discuss granting you further rights as a contributor after your first pull requests, with a maintainer role then being possible after continued interest in the project. activist seeks to be an inclusive, diverse and supportive organization. We'd love to have you on the team!

How you can help

Environment setup

  1. First and foremost, please see the suggested IDE setup in the dropdown below to make sure that your editor is ready for development.

Important

Suggested IDE setup

VS Code

Install the following extensions:

  1. Fork the i18n-check repo, clone your fork, and configure the remotes:

Note

Consider using SSH

Alternatively to using HTTPS as in the instructions below, consider SSH to interact with GitHub from the terminal. SSH allows you to connect without a user-pass authentication flow.

To run git commands with SSH, remember then to substitute the HTTPS URL, https://github.com/..., with the SSH one, git@github.com:....

  • e.g. Cloning now becomes git clone git@github.com:<your-username>/i18n-check.git

GitHub also has their documentation on how to Generate a new SSH key 🔑

# Clone your fork of the repo into the current directory.
git clone https://github.com/<your-username>/i18n-check.git
# Navigate to the newly cloned directory.
cd i18n-check
# Assign the original repo to a remote called "upstream".
git remote add upstream https://github.com/activist-org/i18n-check.git
  • Now, if you run git remote -v you should see two remote repositories named:
    • origin (forked repository)
    • upstream (i18n-check repository)
  1. Create a virtual environment, activate it and install dependencies:

    # Unix or MacOS:
    python3 -m venv venv
    source venv/bin/activate
    
    # Windows:
    python -m venv venv
    venv\Scripts\activate.bat
    
    # After activating venv:
    pip install --upgrade pip
    pip install -r requirements-dev.txt
    
    # To install the CLI for local development:
    pip install -e .

You're now ready to work on i18n-check!

Note

Feel free to contact the team in the Development room on Matrix if you're having problems getting your environment setup!

Contributors

Thanks to all our amazing contributors! ❤️

About

Check i18n/L10n keys and values

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.4%
  • TypeScript 1.6%
0