|
1 |
| -#!/bin/sh |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +SED=sed |
| 6 | + |
| 7 | +if [[ $OSTYPE == 'darwin'* ]]; then |
| 8 | + # for macOS developers, use "brew install gnu-sed" |
| 9 | + SED=gsed |
| 10 | +fi |
| 11 | + |
| 12 | +if [ ! -f ./options/locale/locale_en-US.ini ]; then |
| 13 | + echo "please run this script in the root directory of the project" |
| 14 | + exit 1 |
| 15 | +fi |
2 | 16 |
|
3 | 17 | mv ./options/locale/locale_en-US.ini ./options/
|
4 | 18 |
|
5 |
| -# Make sure to only change lines that have the translation enclosed between quotes |
6 |
| -sed -i -r -e '/^[a-zA-Z0-9_.-]+[ ]*=[ ]*".*"$/ { |
7 |
| - s/^([a-zA-Z0-9_.-]+)[ ]*="/\1=/ |
8 |
| - s/\\"/"/g |
| 19 | +# the "ini" library for locale has many quirks |
| 20 | +# * `a="xx"` gets `xx` (no quote) |
| 21 | +# * `a=x\"y` gets `x\"y` (no unescaping) |
| 22 | +# * `a="x\"y"` gets `"x\"y"` (no unescaping, the quotes are still there) |
| 23 | +# * `a='x\"y'` gets `x\"y` (no unescaping, no quote) |
| 24 | +# * `a="foo` gets `"foo` (although the quote is not closed) |
| 25 | +# * 'a=`foo`' works like single-quote |
| 26 | +# crowdin needs the strings to be quoted correctly and doesn't like incomplete quotes |
| 27 | +# crowdin always outputs quoted strings if there are quotes in the strings. |
| 28 | + |
| 29 | +# this script helps to unquote the crowdin outputs for the quirky ini library |
| 30 | +# * find all `key="...\"..."` lines |
| 31 | +# * remove the leading quote |
| 32 | +# * remove the trailing quote |
| 33 | +# * unescape the quotes |
| 34 | +# * eg: key="...\"..." => key=..."... |
| 35 | +$SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { |
| 36 | + s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/ |
9 | 37 | s/"$//
|
| 38 | + s/\\"/"/g |
10 | 39 | }' ./options/locale/*.ini
|
11 | 40 |
|
| 41 | +# * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks |
| 42 | +# * eg: key="... => key=`"...` |
| 43 | +# * eg: key=..." => key=`..."` |
| 44 | +$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini |
| 45 | +$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini |
| 46 | + |
12 | 47 | # Remove translation under 25% of en_us
|
13 | 48 | baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1)
|
14 | 49 | baselines=$((baselines / 4))
|
|
0 commit comments