Giter VIP home page Giter VIP logo

objc_strings's Introduction

Goal

Helps Cocoa applications localization by detecting unused and missing keys in '.strings' files.

Input

Path of an Objective-C project.

Output

  1. warnings for untranslated strings in *.m
  2. warnings for unused keys in Localization.strings
  3. errors for keys defined twice or more in the same .strings file

Typical usage

$ python objc_strings.py -p /path/to/obj_c/project
./MyProject/en.lproj/Localizable.strings:13: warning: unused key in en.lproj: "Misc"
./MyProject/ViewController.m:16: warning: missing key in fr.lproj: "World"

Xcode integration

  1. make objc_strings.py executable

    $ chmod +x objc_strings.py

  2. copy objc_strings.py to the root of your project

  3. add a "Run Script" build phase to your target

  4. move this build phase in second position

  5. set the script path to "${SOURCE_ROOT}/objc_strings.py"

settings warnings

Common Issues

Some may experience UnicodeDecodeError when running the script. The problem is that the script runs through all directories to look for .strings files, which may include already compile .strings files which can not be parsed. Often you have some in Build/ or if you integrate CocoaPods ( Pods/ )

To prevent this you can add dirs which you want to have excluded like this

"${SRCROOT}/objc_strings.py" --exclude-dirs=['Build','Pods']

or if you are on terminal

$ objc_strings.py --project-path /path/to/obj_c/project --exclude-dirs=['Build','Pods']

ToDo

  • Scan Interface Builder (.xib) Files for localized Strings

objc_strings's People

Contributors

albertschulz avatar dmi3j avatar modamoda avatar nst avatar sirnacnud avatar swissquote-nst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

objc_strings's Issues

Error returned when executing script: "UnicodeDecodeError"

When executing the script I get the following in the command line:
Traceback (most recent call last):
File "./scripts/build/objc_strings.py", line 207, in
main()
File "./scripts/build/objc_strings.py", line 204, in main
show_untranslated_keys_in_project(project_path)
File "./scripts/build/objc_strings.py", line 175, in show_untranslated_keys_in_project
keys_set_in_strings = keys_set_in_strings_file_at_path(p)
File "./scripts/build/objc_strings.py", line 97, in keys_set_in_strings_file_at_path
for s in f:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 684, in next
return self.reader.next()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 615, in next
line = self.readline()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 530, in readline
data = self.read(readsize, firstline=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 477, in read
newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xdf in position 8: invalid continuation byte

Crash

Traceback (most recent call last):
File "objc_strings.py", line 189, in
main()
File "objc_strings.py", line 186, in main
show_untranslated_keys_in_project(project_path)
File "objc_strings.py", line 152, in show_untranslated_keys_in_project
keys_set_in_code = keys_set_in_code_at_path(project_path)
File "objc_strings.py", line 140, in keys_set_in_code_at_path
keys = localized_strings_at_path(p)
File "objc_strings.py", line 114, in localized_strings_at_path
s = unicode(s, 'utf-8') #s.decode('utf-8', 'ignore')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc9 in position 107: invalid continuation byte

encoding problem within unicode() function

while testing this useful tool for my iOS projects I ran into this issue :

% python objc_strings.py ~/Projects/pathToMyProject
Traceback (most recent call last):
File "objc_strings.py", line 189, in
main()
File "objc_strings.py", line 186, in main
show_untranslated_keys_in_project(project_path)
File "objc_strings.py", line 152, in show_untranslated_keys_in_project
keys_set_in_code = keys_set_in_code_at_path(project_path)
File "objc_strings.py", line 140, in keys_set_in_code_at_path
keys = localized_strings_at_path(p)
File "objc_strings.py", line 114, in localized_strings_at_path
s = unicode(s)#s.decode('utf-8', 'ignore')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)

after some googling it seems that, in my case (maybe not everyone's), I needed to specify the encoding to be used by the "unicode()" function on line 114, in my case --> utf8.

# s = unicode(s)#s.decode('utf-8', 'ignore')

I replaced the previous line by the following, and it works now like a charm :

s = unicode(s, 'utf8')#s.decode('utf-8', 'ignore')

Hope that helps...

thanks for your work,

Paul

Can this be made to work with utf-16 files?

Hi. Great script.

However, I’m using it in conjunction with this script, https://github.com/joaomoreno/Green-Apples/blob/master/localize.py, which defaults to utf-16, which is causing issues.

Is there any way of modifying this script so that it handles utf-16 rather than utf-8?

(Especially as Apple itself recommends localisation string files be in utf-16: https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPInternational/Articles/StringsFiles.html)

I would have a go myself, but my Python is—not to put too fine a point on it—pretty bad. The use of white space for syntax did my head in.

Cheers

Andy W

Shell Scriptinvocation Error

Thanks Nicolas, This is what I am looking for, But I am unable to run this. I am getting Shell Scriptinvocation Erro. It print all the details like

setenv ACTION build
setenv AD_HOC_CODE_SIGNING_ALLOWED NO
setenv ALTERNATE_GROUP staff

and so on, After that it fails & give below error

/Users/mac10/Library/Developer/Xcode/DerivedData/Appname-csvszbiaqhgokgfjvwwwvhujpyui/Build/Intermediates/Appname.build/Debug-iphonesimulator/Appname.build/Script-7ACFF2D6187C165400CB87CA.sh: line 2: /mangesh/Current: No such file or directory

Can you please help me to solve this issue. I don't have any Knowledge of Paython. Thanks

Feature request: custom prefix support

Some project use their own localised macros prefixes. Like
DMLocalizedString(key, comment) instead of normal NSLocalizedString(key, comment). Would be nice to support this in arguments. For example:
"${SRCROOT}/objc_strings.py" --exclude-dirs=['Build','Pods'] --custom-prefix='DM'

Check out

Hey, do you think something like this could be of your interest? What do you think if we merge our work somehow?

LICENSE.md

License of this project is not described.
Could you add LICENSE.md or describe license information in README.md?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.