Convert Localizable.strings tools to UTF-8 (#1420)

- Update translations
- Updated transifex scripts to convert appropriately
- Run script from any dir
- Check that target directories exist
- We're currently not pulling any strings from JSQMVC

UTF-8 is preferred since we can see diffs in GH and have sane merges.

// FREEBIE
This commit is contained in:
Michael Kirk 2016-11-29 16:54:01 -05:00 committed by GitHub
parent 896dd026d2
commit f0461891e0
44 changed files with 38 additions and 13 deletions

View File

@ -42,7 +42,7 @@ typedef NS_ENUM(NSUInteger, AboutTableViewControllerSection) {
- (void)loadView {
[super loadView];
self.title = NSLocalizedString(@"SETTINGS_ABOUT", @"");
self.title = NSLocalizedString(@"SETTINGS_ABOUT", @"Navbar title");
// Version
self.versionCell = [[UITableViewCell alloc] init];

View File

@ -2078,14 +2078,14 @@ typedef enum : NSUInteger {
handler:nil];
[actionSheetController addAction:cancelAction];
UIAlertAction *takeMediaAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TAKE_MEDIA_BUTTON", @"")
UIAlertAction *takeMediaAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"MEDIA_FROM_CAMERA_BUTTON", @"media picker option to take photo or video")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[self takePictureOrVideo];
}];
[actionSheetController addAction:takeMediaAction];
UIAlertAction *chooseMediaAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"CHOOSE_MEDIA_BUTTON", @"")
UIAlertAction *chooseMediaAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"MEDIA_FROM_LIBRARY_BUTTON", @"media picker option to choose from library")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[self chooseFromLibrary];

View File

@ -245,14 +245,14 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
handler:nil];
[actionSheetController addAction:dismissAction];
UIAlertAction *takePictureAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TAKE_PICTURE_BUTTON", @"")
UIAlertAction *takePictureAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"MEDIA_FROM_CAMERA_BUTTON", @"media picker option to take photo or video")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[self takePicture];
}];
[actionSheetController addAction:takePictureAction];
UIAlertAction *choosePictureAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"CHOOSE_MEDIA_BUTTON", @"")
UIAlertAction *choosePictureAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"MEDIA_FROM_LIBRARY_BUTTON", @"media picker option to choose from library")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[self chooseFromLibrary];

View File

@ -1,19 +1,28 @@
#!/bin/bash
TARGETS="Signal/src Libraries/EPContactsPicker ../SignalServiceKit/src Pods/JSQMessagesViewController"
TARGETS="Signal/src ../SignalServiceKit/src"
TMP="$(mktemp -d)"
STRINGFILE="Signal/translations/en.lproj/Localizable.strings"
# Make sure we are in the right place
if [ ! -d "Signal/src" ]; then
echo "Please run this tool from the repository's base directory"
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT=$BIN_DIR/../../..
cd $REPO_ROOT
for TARGET_DIR in $TARGETS
do
if [ ! -d $TARGET_DIR ]; then
echo "Unable to find required directory: ${TARGET_DIR}."
exit 1
fi
done
# Search directories for .m & .h files and collect string definitions with genstrings
find $TARGETS -name "*.m" -print0 -o -name "*.h" -print0 -o -name "*.swift" -print0 | xargs -0 genstrings -o $TMP
# We have to convert the old and new .strings files to UTF-8 in order to deal with them
OLDUTF8=$(iconv -f UTF-16 -t UTF-8 $STRINGFILE)
# We have to convert the new .strings files to UTF-8 in order to deal with them
# STRINGFILE is already UTF-8.
OLDUTF8=$(cat $STRINGFILE)
NEWUTF8=$(iconv -f UTF-16 -t UTF-8 $TMP/Localizable.strings)
# Let's merge the old with the new .strings file:
@ -29,5 +38,4 @@ echo "$OLDUTF8" | grep -Eo '^".*"' | \
{$2 = ($1 in a ? a[$1] : $2); \
if($2 ~ /"[;]*$/){$2 = " = "$2}; \
if($2 ~ /"$/){$2 = $2";"}; \
print}' - <(echo "$NEWUTF8") | \
iconv -f UTF-8 -t UTF-16 > $STRINGFILE
print}' - <(echo "$NEWUTF8") > $STRINGFILE

View File

@ -11,6 +11,23 @@ tx pull -a --minimum-perc=80
# Once supported, we don't want to drop any translations.
tx pull --force
for dir in *.lproj
do
# en.lproj is already utf-8
if [[ "$dir" = "en.lproj" ]]; then
continue
fi
pushd $dir
# Transifex pulls utf-16, but our string linting script needs utf-8.
# Plus we can see the string diffs in GH this way.
iconv -f utf-16 -t utf-8 Localizable.strings > Localizable.strings.utf8
mv Localizable.strings.utf8 Localizable.strings
popd
done
# Get and build iStringsCheck from https://github.com/FredericJacobs/iStringsCheck
# This does some checks to make sure all strings are present and that interpolated strings have the right number of arguments
../../../iStringsCheck/target/debug/iStringsCheck en.lproj/Localizable.strings .