Skip to content

A GitHub Action to lint and validate localization files, ensuring consistency across different languages in your project.

License

Notifications You must be signed in to change notification settings

konifar/localizable-strings-checker

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

localizable-strings-checker

RSpec Tests MIT License

localizable-strings-checker is a GitHub Action to lint and validate localization files, ensuring consistency across different languages in your project.

Overview

This tool checks Localizable.strings files for the following issues.

1. Consistency in keys comparing to base language

In the case that the keys which are only present in the base language file.

/* en.lproj/Localizable.strings (base language) */
"strings_one" = "first strings";
"strings_two" = "second strings";
/* ja.lproj/Localizable.strings */
"strings_one" = "1つめの文字列";

Detailed message is output if error is found.

    ...
    Checking for key consistency...
      Keys match: false
      🚨 The following keys are only present in the base language file:
        - strings_two

2. Consistency in comments comparing to base language

In the case that the number of comments are different between base language and other language.

/* en.lproj/Localizable.strings (base language) */
"strings_one" = "first strings";
/* extra comment */
"strings_two" = "second strings";
/* ja.lproj/Localizable.strings */
"strings_one" = "1つめの文字列";
"strings_two" = "2つめの文字列";

Detailed message is output if error is found.

    ...
    Checking for comment consistency...
      Comments match: false
      🚨 The following comments are only present in the base language file:
        - strings_two

3. Consistency in replacement strings comparing to base language

In the case that the number of replacement strings are different between base language and other language.

/* en.lproj/Localizable.strings (base language) */
"replacable_string" = "%1$@ and %2$@";
/* ja.lproj/Localizable.strings */
"replacable_string" = "%1$@";

Detailed message is output if error is found.

    ...
    Checking for the presence of replacement and newline characters...
      🚨 The following keys do not contain the replacement characters:
        - 'replacable_string' does not contain ["%2$@"]

4. Existence of improper single '%' characters

In the case that the single '%' character exists in Localizable.strings file. '%%' should be used instead of '%'.

/* en.lproj/Localizable.strings (base language) */
"strings_one" = "100%";

Detailed message is output if error is found.

    ...
    Checking if single '%' characters exist...
      🚨 The following keys contain a single % character:
        - 'strings_one' contains a single % character

Usage

This works on GitHub Actions like below.

# .github/workflows/lint-localizable-strings.yml
name: Lint Localizable.strings

on:
  pull_request:
    branches:
      - main

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Run Lint Action
        uses: konifar/localizable-strings-checker@v1
        with:
          # Project root path to check Localizable.strings. Default is current directory.
          # project-root-path: "./"
          # Base language code to check other language files like 'ja', 'en', prefix of xx.lproj
          base-lang-code: "ja"

Contribution

Contributions are welcome. Please report bugs or suggest features via Issues. Pull requests are also appreciated.

Setup

  1. Clone this repository
git clone https://github.com/konifar/localizable-strings-checker.git
cd localizable-strings-checker
  1. Install the required gems
bundle install
  1. Run command to the example project
ruby ./localizable_strings_checker.rb example ja

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A GitHub Action to lint and validate localization files, ensuring consistency across different languages in your project.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages