Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Last active March 31, 2022 11:43
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save asmallteapot/11227602 to your computer and use it in GitHub Desktop.
Save asmallteapot/11227602 to your computer and use it in GitHub Desktop.
Diff Xcode localizable strings files in Git.
*.strings utf16 diff=localizablestrings
[diff "localizablestrings"]
textconv = "iconv -f utf-16 -t utf-8"
binary = false

Git v1.8.4 has no idea how to diff Xcode .strings files. Here's how to fix that:

  1. Add the bit from .gitconfig to your ~/.gitconfig.
  2. Add the bit from .gitattributes to your project's .gitattributes file. This should be at the root of your project, if one doesn't already exist.
  3. You should now be able to use git diff and git add -p with strings files.

The conversion seems to cause rendering issues for some non-Latin characters in iTerm2 v1.0.0.20140112 on Mac OS 10.9.2, but this doesn't affect the files themselves. If anyone knows how to fix this issue, please add a comment.

@sstigler
Copy link

sstigler commented Dec 2, 2015

I had to change the second line of .gitconfig to textconv = "iconv -t utf-8" to get this to work for me.

@hackenbruder
Copy link

Thank you!

@trekkieyk
Copy link

I'm seeing the line numbers that hold the changes, I think, but it shows a blank diff. I'm using SourceTree on Mac.

Copy link

ghost commented Jul 20, 2017

Thank you guys it was so helpful.
I did : -
*.strings diff=localizablestrings and

[diff "localizablestrings"]
	textconv = "iconv  -t utf-8"

they worked perfectly.

I am not sure the Localizable.strings file is very very different staff. I would not need this kind of staff for any [anyNameOtherThanLocalizable].strings file. I am not sure why? Any idea please

@chrisdarc
Copy link

chrisdarc commented Feb 9, 2018

Instead of messing with git settings, I fixed this issue by:

  1. Creating a new Localizable.strings file - File>New>File... and then select strings file.
  2. Copying contents of old Localizable.strings file to the new one
  3. Deleting old Localizable.strings file

Now git recognizes these files properly and I can see changes and conflicts.

@shyambhat
Copy link

shyambhat commented Feb 20, 2019

Thanks for the gist. This works for me locally with git and Sourcetree. But this isn't helping with the diffs in GitHub pull requests. The diffs do not show on the strings files. Anyone has ideas on how to get that to work?

github-diff

@xieweiAlex
Copy link

I met the same problem. I fixed it by changing the text encoding of Localizable.strings from No explicit Encoding to UTF-16, everything works fine now.

@kerrmarin
Copy link

@shyambhat did you ever get this working on GitHub?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment