Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with genstrings for Swift file

genstrings works well to extract localizable content from .m file as,

find . -name \*.m | xargs genstrings -o en.lproj

But, not working for .swift file as,

find . -name \*.swift | xargs genstrings -o en.lproj
like image 588
BaSha Avatar asked Oct 13 '14 13:10

BaSha


3 Answers

The genstrings tool works fine with swift as far as I am concerned. Here is my test:

// MyClass.swift
let message = NSLocalizedString("This is the test message.", comment: "Test")

then, in the folder with the class

# generate strings for all swift files (even in nested directories)
$ find . -name \*.swift | xargs genstrings -o .

# See results
$ cat Localizable.strings
/* Test */
"This is the test message." = "This is the test message.";
$
like image 180
Mundi Avatar answered Oct 31 '22 23:10

Mundi


I believe genstrings works as intended, however Apple's xargs approach to generate strings from all your project's files is flawed and does not properly parse paths containing spaces.

That might be the reason why it's not working for you.

Try using the following:

find . -name \*.swift | tr '\n' '\0' | xargs -0 genstrings -o .

like image 5
m_katsifarakis Avatar answered Nov 01 '22 00:11

m_katsifarakis


We wrote a command line tool that works for Swift files and merges the result of apples genstrings tool. It allows for key and value in NSLocalizedString

https://github.com/KeepSafe/genstrings_swift

like image 4
philipp Avatar answered Nov 01 '22 01:11

philipp