Check Localizable.strings files of iOS Apps

Overview

Rubustrings Build Status

Check the format and consistency of the Localizable.strings files of iOS Apps with multi-language support

Rubustrings is also available for Android here

Usage

It only needs the files to validate as arguments

rubustrings Localizable.strings

Additionally to the filenames, including the option --onlyformat will only assert for the format.

Install

gem install rubustrings

Validators

Currently Rubustrings validates:

  • The syntaxis of the strings file: Just the format of each line: "key" = "value";
  • Dynamic values (%@, %d, %ld,...): It checks that the translation include the same set of them than the original string.
  • Special characters at the beginning or at the end: If the original string begins or ends with a white space,\n or \r it tests that the translation also does.

It also warning on:

  • Untranslated strings: In missing translations
  • Translation significantly large: In translations 3 times larger than original string

Example

dcordero@silver:~$ rubustrings Localizable.strings
Processing file: "Localizable.strings"

Localizable.strings:217: error: beginning mismatch: "Tubasa" = " Tubasa";
Localizable.strings:220: error: number of variables mismatch: "Web %@" = "Web";
Localizable.strings:225: error: invalid format: "bad format" = "because of a missing quote;

Result: ✘ Some errors detected
dcordero@silver:~$ rubustrings Localizable.strings
Processing file: "Localizable.strings"

Result: ✓ Strings file validated succesfully

XCode

Rubustrings can also be used as a custom build rule so that all .strings files are automatically validated at build time. This will also attempt to highlight offending lines in XCode.

Xcode build rule example

Just add a new "Run Script Phase" with:

if which rubustrings>/dev/null; then
  find "${SRCROOT}" -type f -name Localizable.strings -print0 | xargs -0 -n1 rubustrings
else
  echo "warning: Rubustrings not installed, download from https://github.com/dcordero/Rubustrings"
fi

Xcode setting example

License

MIT License (MIT) Copyright (c) 2017 @dcordero

Comments
  • invalid byte sequence error

    invalid byte sequence error

    Even when processing a valid file (bulgarian), I am getting this error:

    Processing file: "Localizable.strings"

    /usr/local/bin/rubustrings:24:in gsub': invalid byte sequence in UTF-8 (ArgumentError) from /usr/local/bin/rubustrings:24:inremove_comments_and_empty_lines' from /usr/local/bin/rubustrings:80:in validate_localizable_string_file' from /usr/local/bin/rubustrings:94:inblock in

    ' from /usr/local/bin/rubustrings:92:in each' from /usr/local/bin/rubustrings:92:in
    '

    I am by no means knowledgeable of ruby, but perhaps something you are using only works with utf-8?

    bug 
    opened by shawnwall 5
  • error while running

    error while running

    Devanshus:kplms devanshus$ sudo rubustrings Localizable.strings /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- colored (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /Library/Ruby/Gems/2.3.0/gems/rubustrings-0.0.3/lib/rubustrings/action.rb:2:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Library/Ruby/Gems/2.3.0/gems/rubustrings-0.0.3/lib/rubustrings.rb:2:in<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:inrescue in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in require' from /Library/Ruby/Gems/2.3.0/gems/rubustrings-0.0.3/bin/rubustrings:3:in<top (required)>' from /usr/local/bin/rubustrings:22:in load' from /usr/local/bin/rubustrings:22:in

    '

    opened by devanshudew 4
  • String argument position - incorrect validation error

    String argument position - incorrect validation error

    The validation incorrectly fails when the argument position in the translation string is changed like so:

    "%@, %@" = "%2$@ %1$@";
    

    Example: en: "1, Infinite Loop" de: "Infinite Loop 1"

    I just tried to fix this, but I'm a complete regex dead-loss :(

    opened by deberle 3
  • Format string position support

    Format string position support

    Correct issue #4 by expanding the validate_special_characters method. Now it will extract the parameter, length, and type fields from the format strings and does basic checking for format strings with a specified parameter. So something like

    "%@, %d" = "%2$d %1$@";
    

    will now be considered valid. It also checks to make sure that there are no specified parameter arguments in the key, and that if a parameter argument is specified somewhere in the value then it's used everywhere.

    I included a stable sort to handle the case where no parameters are used and I still needed to preserve their original ordering.

    There is a slight conflict with this pull request and the other I made with regards to the tests: the included tests pass on the master branch but with the xcode changes on the other pull request there is a slight change around the way color strings are generated (specifically the coloring formatting surrounding the newline characters, which doesn't affect the visible output but still causes a test fail). For whichever pull request gets included first I'll make sure to update the other to fix the issue.

    opened by rliljest 2
  • XCode 6.3 beta 2

    XCode 6.3 beta 2

    I tried to run it over my file and it says:

    ./rubustrings.rb:17:inread': ""d" on UTF-16 (Encoding::InvalidByteSequenceError) from ./rubustrings.rb:17:in open_and_read_file' from ./rubustrings.rb:79:invalidate_localizable_string_file' from ./rubustrings.rb:94:in block in <main>' from ./rubustrings.rb:92:ineach' from ./rubustrings.rb:92:in <main>'

    opened by danielgomezrico 2
  • Fallback on UTF-8 if we cannot open file in UTF-16

    Fallback on UTF-8 if we cannot open file in UTF-16

    Support UTF-8 in addition to UTF-16. Apple documentation suggests UTF-16 is preferred for strings files, but I know a lot of projects use UTF-8 (including Apple's own ResearchKit)

    opened by rliljest 1
  • Xcode custom build rule integration

    Xcode custom build rule integration

    This change adds a new -xcode flag that could be used to generate xcode-friendly output. This means that if rubustrings is used with this flag as part of a custom build rule or build phase shell script, it will let xcode know the file and line with the error, allowing the developer to double-click on the error to see it in the Xcode file editor.

    It does make the code not quite as elegant: this is also my first time using Ruby so I'm sure there are things I have done that could be done much better.

    There are a couple edge cases where I know this will not work correctly: Mainly if there is a comment that spans multiple lines with text after the closing tag e.g.

    /* multi-line
       comment */"KEY" = "VALUE";
    

    Although I'm not sure if that's a valid use-case to be concerned with.

    Essentially the modifications preprocess the file by adding the line number to the beginning of every line, removes whitespace and comments, and then uses that line number when it generates error output.

    opened by rliljest 1
  • cannot catch this error

    cannot catch this error

    in Localizable.strings, there is a line like this. "Turn off airplane mode or use Wi-Fi to access %@." = "Отключить режим "в самолете" или использовать Wi-Fi для доступа к %@.";

    within the string, quotation marks are not escaped, wrong translation, while rubustring reports it is ok. plutil could catch the error.

    $ plutil -lint test.strings plutil[60246:655609] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 1. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. test.strings: Unexpected character " at line 1029

    opened by djwgit 0
  • error or warning for empty Localizable.string file?

    error or warning for empty Localizable.string file?

    @dcordero if a localizable.string file is empty, maybe it should just a warning, not an error ? thanks. https://github.com/dcordero/Rubustrings/blob/7852877e82af8e4457cdfa4ac8e70badca846fa8/lib/rubustrings/action.rb#L44

    opened by djwgit 0
Owner
David Cordero
David Cordero
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Jan 3, 2023
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.

Installation • Configuration • Usage • Build Script • Donation • Migration Guides • Issues • Contributing • License BartyCrouch BartyCrouch incrementa

Flinesoft 1.3k Jan 1, 2023
Localizations is an OS X app that manages your Xcode project localization files (.strings)

Localizations 0.2 Localizations is an OS X app that manages your Xcode project localization files (.strings). It focuses on keeping .strings files in

Arnaud Thiercelin 129 Jul 19, 2022
Lists missing keys from .strings files.

strings-check A simple command line utility to check if translation strings are missing, or if extra translations are present in a set of .strings fil

Dave Clayton-Wagner 3 Nov 22, 2022
Localize iOS apps in a smarter way using JSON files. Swift framework.

Swifternalization Swift library that helps in localizing apps in a different, better, simpler, more powerful way than system localization does. It use

Tomasz Szulc 575 Nov 3, 2022
Android/iOS Apps created to practice with different iOS/Android Tech. These apps were built to have similar feature sets using native Android/iOS.

AgilityFitTodayApp Android/iOS Apps created to practice with different iOS/Android Tech. These apps were built to have similar feature sets using nati

Lauren Yew 1 Feb 25, 2022
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.

Localize Localize is a framework written in swift to help you localize and pluralize your projects. It supports both storyboards and strings. Features

Andres Silva 279 Dec 24, 2022
Super lightweight library that helps you to localize strings, even directly in storyboards!

Translatio Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 9 or higher. Swi

Andrea Mario Lufino 19 Jan 29, 2022
Minification of localized strings

SmallStrings Reducing localized .strings file sizes by 80% How it works The library consists of two main components: A tool that converts the .strings

Emerge Tools 48 Jan 8, 2023
An application to convert strings to diffirent formats

Localized An application to convert strings to diffirent formats This app will help developers to convert strings from application in one platform to

null 16 Feb 12, 2021
Xcode plugin for quickly creating localized strings

Extractor Localizable Strings Extractor Localizable Strings is a open source plug-in for Xcode. It lets you extract localizable strings without openin

Vinícius Oliveira 220 Jun 29, 2022
Semi-automated Text Translator for Websites and Apps

macOS/Ubuntu/Windows: attranslate is a semi-automated tool for "synchronizing" translation-files. attranslate is optimized for fast and smooth rollout

Felix Kirchengast 272 Dec 21, 2022
Will Powell 1.2k Dec 29, 2022
Crowdin iOS SDK delivers all new translations from Crowdin project to the application immediately

Crowdin iOS SDK Crowdin iOS SDK delivers all new translations from Crowdin project to the application immediately. So there is no need to update this

Crowdin 98 Dec 14, 2022
iOS localization swift code generation project

code-gen-library - localization-swift module code-gen-library - localization-swift module with Python bash script execute to localization swift files(

umut boz 0 Oct 26, 2021
Simple solution to localize your iOS App.

Hodor is a simple solution to localize your iOS App quickly, allow you to change language of project in-app without quiting the app, Just like WeChat.

Aufree 545 Dec 24, 2022
transai is a localization tool on Android and iOS.

transai transai is a command line tool to help you do Android and iOS translation management. You can extract string files to csv format, or generate

Jintin 56 Nov 12, 2022
iOS implementation of the Catrobat language

Catty Catty, also known as Pocket Code for iOS, is an on-device visual programming system for iPhones. Catrobat is a visual programming language and s

null 74 Dec 25, 2022
Demo project of Swift language crash using Release build on iOS 14

Demo project of Swift language crash using Release build on iOS 14 Repro steps O

Daohan Chong 0 Mar 24, 2022