Swiftpack.co - Package - AlexPinhasov/AutoLocalized

A tool to manage localization in your project and show errors and/or warnings when needed.

Platform Author Swift

Behind the scenesInstallationAuthorLicense

AutoLocalized scans your project and search for your localization files and project files containing localized keys. By using Rules and Validation methods ensuring your keys and files are organized, clean, and always up to date with your work.

Behind the scenes

For every localization file found the following is executed:

  • Make sure each row has only 1 key and 1 value.
  • Sort by keys.
  • Validate no duplicate keys exist.
  • Validate all localization files keys match.
  • Validate all keys that are being used.

For every project file found the following is executed:

  • If a localization key is used in the file but missing from the localization files, show a warning for the dead key.

To Do's:

  • ☐ Add support for custom Rules and Validation methods.
  • ☑ ~~Add support for excluding directories.~~
  • ☑ ~~Add support for custom file extension regex.~~
  • ☐ Identify a value is in the correct language of the localization file.
  • ☐ Add Wiki
  • ☐ Finish README.md
  • ☐ Add build and test pass marks

Installation

AutoLocalized is available through SPM (Swift Package Manager). To install it, simply follow the next steps.
  1. Add AutoLocalized as a dependecy using SPM:
    • File -> Swift Packages -> Add Package Dependency

  1. Create a "New Run Script Phase" under you target in "Build Phases" tab and copy the script below.
SDKROOT=macosx

cd ~/Library/Developer/Xcode/DerivedData/${PROJECT_NAME}-*/SourcePackages/checkouts/AutoLocalized
swift run -c release AutoLocalized ${PROJECT_DIR}/${PROJECT_NAME}

  1. Build the project, in your project file you will find a ".autolocalized.yml" configuration file.
  • If you get an "error:invalid Access" error after building, just build agian it will go away. (SPM bug)

Configuration (.autolocalized.yml)

Configure AutoLocalized by adding a .autolocalized.yml file in your project file or building the project once, the framework can create a file when non is found. The following parameters can be configured:

fileExtensions:

  • extension to support
  • regex to search by keys
  • match_index what index in regex match to select

excluded: what directories to ignore

  • Path

disabledRules: what rules to ignore

  • duplicateValue
fileExtensions: # extensions to support (.swift, .xib...).
  - extension: swift
    regex: "(case|return|static let).*?\"([a-z|_]*?)\""
    match_index: 2
  - extension: xib
    regex: "(text|title|value|placeholder)=\"([a-z|_]*?)\""
    match_index: 2
  - extension: storyboard
    regex: "(text|title|value|placeholder)=\"([a-z|_]*?)\""
    match_index: 2
excluded: # paths to ignore.
  - Attribution/
  - Operations/
  - Localization/LocalizableProtocol
disabledRules: # ignore rules by specefing their names
  - duplicateValue

Disable Auto localized

If you only want to exclude a part of your code use

// autolocalized:disable
  {your code }
// autolocalized:enable

Output

In your "Build report" in Xcode, you will see all the files that were found using your .autolocalized.yml configuration, separated by file type. In addition, you will see the number of keys in that files and the keys.

Author

AlexPinhasov, alex5872205@gmail.com

License

AutoLocalized is available under the MIT license. See the LICENSE file for more info.

Github

link
Stars: 2

Dependencies

Used By

Total: 0

Releases

Change Rules error type - 2020-09-10 09:26:32

Change duplicateValue rule from error -> warning

🐛 Fix bugs - 2020-09-10 09:19:49

Duplicate Key/Value rules showed in correct line numbers

Add support for excluding rules - 2020-09-10 08:48:41

in the YAML configuration file, you can now add rules to ignore:

disabledRules:

  • duplicateValue

to prevent that rule from executing

- 2020-09-06 18:24:45

- 2020-09-06 09:42:53

- 2020-09-04 06:38:53

- 2020-09-03 18:09:27

- 2020-09-03 17:53:52

- 2020-09-03 17:31:52

- 2020-09-01 07:53:35

- 2020-09-01 07:46:22

- 2020-09-01 07:24:15

- 2020-08-31 11:58:10

- 2020-08-31 11:34:34

- 2020-08-31 11:31:00

- 2020-08-31 11:26:05

- 2020-08-30 05:03:09

- 2020-08-28 19:07:02

- 2020-08-27 18:46:20

- 2020-08-27 18:40:50

- 2020-08-27 09:15:22

- 2020-08-27 09:08:40

- 2020-08-26 17:39:58

- 2020-08-25 06:22:21

- 2020-08-25 06:11:36

- 2020-08-25 06:08:36

- 2020-08-22 10:05:31

- 2020-08-19 06:52:22

- 2020-08-19 05:57:42

- 2020-08-19 05:51:03