Skip to content

Commit 736c42c

Browse files
authored
Merge pull request #633 from keymanapp/feat/localize-keyboard/crowdin
Add crowdin.yml configuration file 🗺️
2 parents 14b3d66 + 45b0f1d commit 736c42c

File tree

8 files changed

+214
-2
lines changed

8 files changed

+214
-2
lines changed

.htaccess

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ RewriteBase /
2222
# Add mime type for apple-app-site-association
2323
AddType application/json apple-app-site-association
2424

25+
# Deny crowdin.yml
26+
RewriteRule ^crowdin.yml$ = [F,L]
27+
2528
# Custom error messages
2629
# ErrorDocument 404 /_includes/errors/404.php
2730

_includes/locale/strings/keyboards/details/en.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Keyman is copyright (C) SIL Global. MIT License.
55
*
66
* Default English strings for keyboards/keyboard-details.php
7+
* When exporting strings from crowdin, convert \\$s to \$s
78
*/
89

910
declare(strict_types=1);

_includes/locale/strings/keyboards/details/fr.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Keyman is copyright (C) SIL Global. MIT License.
55
*
66
* French strings for keyboards/index.php
7+
* When exporting strings from crowdin, convert \\$s to \$s
78
*/
89

910
declare(strict_types=1);

_includes/locale/strings/keyboards/en.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Keyman is copyright (C) SIL Global. MIT License.
55
*
66
* Default English strings for keyboards/index.php
7+
* Don't escape $s when uploading source to crowdin because exports will escape \$s to \\$s
78
*/
89

910
declare(strict_types=1);

_includes/locale/strings/keyboards/install/en.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Keyman is copyright (C) SIL Global. MIT License.
55
*
66
* Default English strings for keyboards/keyboard-install.php
7-
* Use placeholders like %1\$s
7+
* When exporting strings from crowdin, convert \\$s to \$s
88
*/
99

1010
declare(strict_types=1);

_includes/locale/strings/keyboards/share/en.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Keyman is copyright (C) SIL Global. MIT License.
55
*
66
* Default English strings for keyboards/keyboard-share.php
7-
* Use placeholders like %1\$s
7+
* When exporting strings from crowdin, convert \\$s to \$s
88
*/
99

1010
declare(strict_types=1);

crowdin.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#
2+
# Shared Crowdin control for https://keyman.com
3+
#
4+
5+
#
6+
# Your Crowdin credentials
7+
#
8+
project_id_env: "KEYMAN_COM_CROWDIN_PROJECT_ID"
9+
api_token_env: "CROWDIN_PERSONAL_TOKEN"
10+
base_path: "." # local base path
11+
base_url: "https://api.crowdin.com"
12+
13+
#
14+
# Choose file structure in Crowdin
15+
# e.g. true or false
16+
#
17+
preserve_hierarchy: true
18+
19+
#
20+
# Files configuration
21+
#
22+
files:
23+
# source: local path of file that gets uploaded to crowdin
24+
# dest: crowdin path in https://crowdin.com/project/keymancom
25+
# translation: local path where downloaded translations from crowdin go
26+
27+
28+
# Keyboard search files
29+
30+
- source: /_includes/locale/strings/keyboards/en.php
31+
dest: /keyboards/keyboards/en.php
32+
translation: /_includes/locale/strings/keyboards/%locale%.php
33+
languages_mapping:
34+
locale:
35+
# Canonical locales as needed
36+
es-ES: es
37+
de: de
38+
fr: fr
39+
km: km
40+
41+
- source: /_includes/locale/strings/keyboards/details/en.php
42+
dest: /keyboards/keyboards-details/en.php
43+
translation: /_includes/locale/strings/keyboards/details/%locale%.php
44+
languages_mapping:
45+
locale:
46+
# Canonical locales as needed
47+
es-ES: es
48+
de: de
49+
fr: fr
50+
km: km
51+
52+
- source: /_includes/locale/strings/keyboards/install/en.php
53+
dest: /keyboards/keyboards-install/en.php
54+
translation: /_includes/locale/strings/keyboards/install/%locale%.php
55+
languages_mapping:
56+
locale:
57+
# Canonical locales as needed
58+
es-ES: es
59+
de: de
60+
fr: fr
61+
km: km
62+
63+
- source: /_includes/locale/strings/keyboards/share/en.php
64+
dest: /keyboards/keyboards-share/en.php
65+
translation: /_includes/locale/strings/keyboards/share/%locale%.php
66+
languages_mapping:
67+
locale:
68+
# Canonical locales as needed
69+
es-ES: es
70+
de: de
71+
fr: fr
72+
km: km
73+
74+
# crowdin parameters descriptions:
75+
76+
#
77+
# Source files filter
78+
# e.g. "/resources/en/*.json"
79+
#
80+
81+
#
82+
# Where translations will be placed
83+
# e.g. "/resources/%two_letters_code%/%original_file_name%"
84+
#
85+
#"translation" : "",
86+
87+
#
88+
# Files or directories for ignore
89+
# e.g. ["/**/?.txt", "/**/[0-9].txt", "/**/*\?*.txt"]
90+
#
91+
#"ignore" : [],
92+
93+
#
94+
# The dest allows you to specify a file name in Crowdin
95+
# e.g. "/messages.json"
96+
#
97+
#"dest" : "",
98+
99+
#
100+
# File type
101+
# e.g. "json"
102+
#
103+
#"type" : "",
104+
105+
#
106+
# The parameter "update_option" is optional. If it is not set, after the files update the translations for changed strings will be removed. Use to fix typos and for minor changes in the source strings
107+
# e.g. "update_as_unapproved" or "update_without_changes"
108+
#
109+
#"update_option" : "",
110+
111+
#
112+
# Start block (for XML only)
113+
#
114+
115+
#
116+
# Defines whether to translate tags attributes.
117+
# e.g. 0 or 1 (Default is 1)
118+
#
119+
# "translate_attributes" : 1,
120+
121+
#
122+
# Defines whether to translate texts placed inside the tags.
123+
# e.g. 0 or 1 (Default is 1)
124+
#
125+
# "translate_content" : 1,
126+
127+
#
128+
# This is an array of strings, where each item is the XPaths to DOM element that should be imported
129+
# e.g. ["/content/text", "/content/text[@value]"]
130+
#
131+
# "translatable_elements" : [],
132+
133+
#
134+
# Defines whether to split long texts into smaller text segments
135+
# e.g. 0 or 1 (Default is 1)
136+
#
137+
# "content_segmentation" : 1,
138+
139+
#
140+
# End block (for XML only)
141+
#
142+
143+
#
144+
# Start .properties block
145+
#
146+
147+
#
148+
# Defines whether single quote should be escaped by another single quote or backslash in exported translations
149+
# e.g. 0 or 1 or 2 or 3 (Default is 3)
150+
# 0 - do not escape single quote;
151+
# 1 - escape single quote by another single quote;
152+
# 2 - escape single quote by backslash;
153+
# 3 - escape single quote by another single quote only in strings containing variables ( {0} ).
154+
#
155+
# "escape_quotes" : 3,
156+
157+
#
158+
# Defines whether any special characters (=, :, ! and #) should be escaped by backslash in exported translations.
159+
# e.g. 0 or 1 (Default is 0)
160+
# 0 - do not escape special characters
161+
# 1 - escape special characters by a backslash
162+
#
163+
# "escape_special_characters": 0
164+
#
165+
166+
#
167+
# End .properties block
168+
#
169+
170+
#
171+
# Often software projects have custom names for the directories where translations are placed. crowdin-cli allows you to map your own languages to be understandable by Crowdin.
172+
#
173+
#"languages_mapping" : {
174+
# "two_letters_code" : {
175+
# "crowdin_language_code" : "local_name"
176+
# }
177+
#},
178+
179+
#
180+
# Does the first line contain header?
181+
# e.g. true or false
182+
#
183+
#"first_line_contains_header" : true,
184+
185+
#
186+
# for spreadsheets
187+
# e.g. "identifier,source_phrase,context,uk,ru,fr"
188+
#
189+
# "scheme" : "",

resources/init-container.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@ else
1313
echo "Skip Generating CDN and clean CDN cache"
1414
rm -rf "$THIS_SCRIPT_PATH/../cdn/deploy"
1515
fi
16+
# PHP localization strings need to have '$' escaped like '%1\$s'.
17+
# But the download files from Crowdin get escaped again as '%1\\$s'.
18+
# Reverts to escaping once.
19+
cd "$THIS_SCRIPT_PATH/../_includes/locale/strings"
20+
21+
find . -type f -name "*.php" -print0 | while IFS= read -r -d '' file; do
22+
# Not doing sed in-place to avoid permission errors
23+
sed -r 's/([0-9])\\{2}\$/\1\\\$/g' "$file" > temp
24+
25+
if [ $? -ne 0 ]; then
26+
echo "ERROR cleaning up files: $file"
27+
exit 1
28+
fi
29+
30+
mv temp "$file"
31+
32+
done

0 commit comments

Comments
 (0)