'Bash : Read each line of Localizable.strings
In Xcode we have a Localizable.string file we used to support multiple languages in our app. I want to spell check the Localizable.string file. When I use this script the output gets printed to the console
cat ~/Desktop/Localizable.strings
But when I try to read line by line to spell check using this script a bunch of blank lines are printed to the console.
cat ~/Desktop/Localizable.strings | while read line; do
echo $line
done
This is how the Localizable.strings file looks like. It has a key and a value. I only want to check the Value
"SOME_KEY" = "Spell check this";
Any ideas?
Solution 1:[1]
This will print all values of a specified Localizable.strings file
plutil -p $FILE_PATH | grep '" *=> *"' | while read line; do
key=$(echo "$line" | sed -E 's/(.*)=>(.*)/\2/')
echo $key
done
Solution 2:[2]
Here is the Swift 5 version of @user529758's answer:
import Foundation
// ref: https://stackoverflow.com/a/15426631
let path = CommandLine.arguments[1]
let url = URL(fileURLWithPath: path)
let dict = NSDictionary.init(contentsOf: url)
for value in dict?.allValues ?? [] {
print(key)
}
run via swift main.swift /path/to/Localizable.strings
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tristan Richard |
| Solution 2 | jangelsb |
