From 7b02e3ff704d028fea8653ff63139c674c3226b3 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Wed, 31 Oct 2007 22:39:19 +0200 Subject: [PATCH] Convert *.strings to UTF-16 at build time. "Note: Strings files encoded using UTF-8 are not guaranteed to work. When in doubt, encode the file using UTF-16." However, Git does not display readable diffs for UTF-16 files. So keep *.strings files as UTF-8 in the source tree, but convert them to UTF-16 during the build. Not all the strings files in the source tree are in UTF-8 yet, and not all of the UTF-8 ones begin with a byte-order mark. I intend to convert files to UTF-8 with BOM as I modify them. --- MacTF.xcodeproj/project.pbxproj | 17 +++++++++++++++++ to-UTF-16.pl | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 to-UTF-16.pl diff --git a/MacTF.xcodeproj/project.pbxproj b/MacTF.xcodeproj/project.pbxproj index bf6e0c5..900038e 100644 --- a/MacTF.xcodeproj/project.pbxproj +++ b/MacTF.xcodeproj/project.pbxproj @@ -73,6 +73,20 @@ FFE483AC0CCDC38400DC3B45 /* TFUSBControllerCommunicationBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = FFE483AA0CCDC38400DC3B45 /* TFUSBControllerCommunicationBlock.m */; }; /* End PBXBuildFile section */ +/* Begin PBXBuildRule section */ + FF6AEA8B0CD90329004AA180 /* PBXBuildRule */ = { + isa = PBXBuildRule; + compilerSpec = com.apple.compilers.proxy.script; + filePatterns = "*.strings"; + fileType = pattern.proxy; + isEditable = 1; + outputFiles = ( + "${DERIVED_FILES_DIR}/${INPUT_FILE_REGION_PATH_COMPONENT}${INPUT_FILE_NAME}", + ); + script = "./to-UTF-16.pl \"${INPUT_FILE_REGION_PATH_COMPONENT}${INPUT_FILE_NAME}\" \"${DERIVED_FILES_DIR}/${INPUT_FILE_REGION_PATH_COMPONENT}${INPUT_FILE_NAME}\""; + }; +/* End PBXBuildRule section */ + /* Begin PBXContainerItemProxy section */ FFD5623A0CBF60430099621D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -178,6 +192,7 @@ C1E0460C0946D7E600B808CA /* mp3.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = mp3.tif; sourceTree = ""; }; C1E0460E0946D7F300B808CA /* txt.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = txt.tif; sourceTree = ""; }; FF10EEF20CC123890027156F /* COPYING */ = {isa = PBXFileReference; fileEncoding = 7; lastKnownFileType = text; path = COPYING; sourceTree = ""; }; + FF6AEABB0CD919E5004AA180 /* to-UTF-16.pl */ = {isa = PBXFileReference; explicitFileType = text.script.perl; fileEncoding = 4; path = "to-UTF-16.pl"; sourceTree = ""; }; FFD562350CBF60420099621D /* iLifeControls.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = iLifeControls.xcodeproj; path = iLifeControls/iLifeControls.xcodeproj; sourceTree = ""; }; FFE483A90CCDC38400DC3B45 /* TFUSBControllerCommunicationBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TFUSBControllerCommunicationBlock.h; sourceTree = ""; }; FFE483AA0CCDC38400DC3B45 /* TFUSBControllerCommunicationBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TFUSBControllerCommunicationBlock.m; sourceTree = ""; }; @@ -255,6 +270,7 @@ 29B97314FDCFA39411CA2CEA /* MacTF */ = { isa = PBXGroup; children = ( + FF6AEABB0CD919E5004AA180 /* to-UTF-16.pl */, FF10EEF20CC123890027156F /* COPYING */, C16FADEB06C75BF100EE0B5E /* ToDo */, C16FADEF06C75C0200EE0B5E /* ChangeLog */, @@ -399,6 +415,7 @@ 8D11072E0486CEB800E47090 /* Frameworks */, ); buildRules = ( + FF6AEA8B0CD90329004AA180 /* PBXBuildRule */, ); dependencies = ( FFD562400CBF60790099621D /* PBXTargetDependency */, diff --git a/to-UTF-16.pl b/to-UTF-16.pl new file mode 100755 index 0000000..042e93a --- /dev/null +++ b/to-UTF-16.pl @@ -0,0 +1,37 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my($in_name, $out_name) = @ARGV; + +open my $in_h, "<", $in_name or die "$in_name: $!"; +binmode $in_h or die "$in_name: $!"; +my $head; +defined(read $in_h, $head, 4) or die "$in_name: $!"; +close $in_h or die "$in_name: $!"; + +my $charset; +if ($head =~ /^\x00\x00\xFF\xFE/) { + print "$in_name: Found big-endian UTF-32 BOM\n"; + $charset = "UTF-32"; +} elsif ($head =~ /^\xFE\xFF\x00\x00/) { + print "$in_name: Found little-endian UTF-32 BOM\n"; + $charset = "UTF-32"; +} elsif ($head =~ /^\xFE\xFF/) { + print "$in_name: Found big-endian UTF-16 BOM\n"; + $charset = "UTF-16"; +} elsif ($head =~ /^\xFF\xFE/) { + print "$in_name: Found little-endian UTF-16 BOM\n"; + $charset = "UTF-16"; +} elsif ($head =~ /^\xEF\xBB\xBF/) { + print "$in_name: Found UTF-8 BOM\n"; + $charset = "UTF-8"; +} else { + print "$in_name: No BOM found -- assuming UTF-8\n"; + $charset = "UTF-8"; +} + +open STDOUT, ">", $out_name or die "$out_name: $!"; +exec "iconv", "-f", $charset, "-t", "UTF-16", $in_name + or die "exec iconv: $!"; -- 2.11.4.GIT