Skip to content

Commit 95f11e0

Browse files
authored
Merge pull request github#359 from github/i18n-updates
I18n: Keeping translations updated
2 parents d449c06 + df24702 commit 95f11e0

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

docs/translations.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ If there's not, then today is your day to lead this effort! Here's how to start:
1414

1515
## Keeping a translation updated
1616

17-
TODO
17+
Git is pretty good at tracking files that have changed. We'll try to make it as easy as possible for you to keep your translation up to date.
18+
19+
Note: These directions assume the `origin` [remote](https://git-scm.com/docs/git-remote) is the translation fork. If you didn't originally clone the repository from the fork, you can update it with `git remote set-url origin https://github.com/[yourname]/opensource.guide.git`.
20+
21+
Here is the recommended process:
22+
23+
0. Run `$ script/sync-translation` to merge the latest changes from upstream and open a Pull Request on your fork.
24+
0. If files requiring translation have been modified, they will be added to a checklist in the Pull Request.
25+
0. Once all files have been updated, merge the pull request.
1826

19-
should be easy to merge in changes from upstream without conflicts
27+
Run this script as often as you want to keep your translation up to date.

script/sync-translation

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
#
3+
# Sync changes from upstream and open a pull request
4+
#
5+
# Usage: script/sync-upstream [remote]
6+
#
7+
# TODO:
8+
# - [ ] handle merge conflicts with `git merge --continue`
9+
10+
set -e
11+
12+
which -s hub || (echo "This script requires the 'hub' command: http://hub.github.com/" && exit 1)
13+
14+
# If there's not an upstream remote, set it.
15+
if ! git remote show | grep -q upstream; then
16+
git remote add upstream https://github.com/github/opensource.guide.git
17+
fi
18+
19+
REMOTE=${1:-"origin"}
20+
BASE="$REMOTE/gh-pages"
21+
# FIXME: switch to upstream/gh-pages before this is merged:
22+
# https://github.com/github/open-source-guide/pull/295
23+
HEAD="upstream/i18n"
24+
25+
git fetch upstream
26+
git fetch $REMOTE
27+
28+
BASE_SHA=$(git rev-parse $BASE)
29+
HEAD_SHA=$(git rev-parse $HEAD)
30+
BRANCH="sync-${HEAD_SHA:0:8}"
31+
32+
TRANSLATABLE_FILES="
33+
_articles
34+
_data/locale/en-US.yml
35+
_config
36+
"
37+
38+
## Create a new branch and merge in the changes from upstream.
39+
echo "Creating branch $BRANCH based off $BASE"
40+
git checkout -B $BRANCH $BASE
41+
echo "Merging in latest changes from $HEAD"
42+
git merge -q --no-edit $HEAD
43+
git push $REMOTE $BRANCH
44+
45+
CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA -- $TRANSLATABLE_FILES)
46+
47+
TEMPLATE="Sync changes from upstream\n\n"
48+
49+
if [ -z "$CHANGED_FILES" ]; then
50+
TEMPLATE="$TEMPLATE\nNo files that need translation were changed upstream."
51+
else
52+
TEMPLATE="$TEMPLATE\nCheck the changes in each of these files and update the translation accordingly:\n"
53+
54+
for file in $CHANGED_FILES; do
55+
TEMPLATE="$TEMPLATE\n- [ ] \`$file\`"
56+
done
57+
fi
58+
59+
OWNER=$(git config --get remote.$REMOTE.url | sed -Ene 's#.*github.com[/:]([^/]*)/.*#\1#p')
60+
61+
echo $TEMPLATE | hub pull-request -o -F - -b $OWNER:gh-pages -h $OWNER:$BRANCH

0 commit comments

Comments
 (0)