0

I have two branches:

master and translation

Basically, translation is the same, but all strings are in Spanish, instead of English.

I worked on some new features on my master branch, and I would like to have these features on my translation branch also.

But how do I do this without overwriting all my spanish strings with english strings?

Is it cherry-pick? And do I have other options, where I do not loose merging functionality, like bdonlan's answer on how to merge a specific commit in Git?

  • 2
    Using SCM branches for internationalization is probably not a good idea. Use "resource files" or similar. – John Zwinck Sep 14 '17 at 12:32
  • Despite what @JohnZwinck and @TimBegeleisen said that is verry correct, `git cherry-pick` can help you to pick specific commits without merging the whole thing. You have to separate commits that touch strings from those that introduce new features, and only cherry pick the latter ones. – kowsky Sep 14 '17 at 12:36
  • @kowsky Remember that a commit in Git is conceptually a snapshot of _all_ files, not just the ones which were changed in the actual commit. Doing _any_ sort of merge or cherry-pick between the English and Spanish branches not only runs the risk of conflict, it runs the risk of one language version being entirely overwritten by the other. – Tim Biegeleisen Sep 14 '17 at 12:42
  • Hi karl, are the changes made across many of the files in your master or just one? – robstarbuck Sep 14 '17 at 13:41
  • @robstarbuck, on many files. – Karl Kristiansen Sep 14 '17 at 14:25
  • My examples were misleading. I am not using branches to do translations of an app, I just needed an example that is better than my real situation. I'm going to leave it like this, because it's solid advice for people stumbling in here looking for ways to use Git in localizations and translations. – Karl Kristiansen Sep 14 '17 at 14:28

1 Answers1

2

I'm going to give an answer which departs somewhat from Git because I believe its point is important. It is bad design to keep separate branches for different languages. As you are now seeing, if you make a feature improvement in one branch and wish to bring it into the other branch, you cannot do so easily.

Instead, look into using message bundles, which can handle multi language support all from a logically single application. Java, JavaScript and most languages support bundles.

If you absolutely must proceed on your current path, then you have no choice but to do the merge or cherry-pick and live up to the chance that some of your language material may be overwritten. Let's consider the worst possible scenario and how you might handle it.

Let's say you did a cherry-pick from master into translation which resulted in all of your Spanish language support code being overwritten with English code. Let's make it uglier and assume that there weren't even any merge conflicts, i.e. Git happily brought in the feature and overwrote the Spanish code without making a peep. Now you have a commit sitting there, but you can deal with this in several ways. You could revert each language-specific file with its Spanish parent, and then amend the commit via:

git commit --amend

This would rewrite that cherry-pick or merge commit the way you intended it to be, namely with the new feature and your Spanish language specific code intact.

As you can sense, if you continue down this road it could get ugly, so consider making use of language bundles.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360