Skip to content

Commit 7c2bb44

Browse files
committed
Add bash script to autogenerate localized content.
1 parent 3a83be2 commit 7c2bb44

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

i18n/tldr.pot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
10-
"POT-Creation-Date: 2019-02-18 19:31+0100\n"
10+
"Report-Msgid-Bugs-To: https://github.com/tldr-pages/tldr/issues\n"
11+
"POT-Creation-Date: 2019-02-19 22:27+0100\n"
1112
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1213
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1314
"Language-Team: LANGUAGE <[email protected]>\n"

po4a.conf

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
#
2-
# To only genereate translation files:
3-
# po4a -v -k 0 --no-translations po4a.conf
4-
#
5-
# To regenerate translation files and translated pages:
6-
# po4a -v -k 0 po4a.conf
7-
#
8-
# To update the file list:
9-
# for FILE in `tree -f -i pages | grep ".md"`; do echo [type: asciidoc] $FILE \$lang:pages.\$lang/`echo $FILE | cut -d"/" -f 2`/`echo $FILE | cut -d"/" -f 3`; done
1+
# WARNING: this file is generated with translation-update.sh
2+
# DO NOT modify this file manually!
103

114
[po4a_langs] hu
125
[po4a_paths] i18n/tldr.pot $lang:i18n/tldr.$lang.po
@@ -1304,4 +1297,3 @@
13041297
[type: asciidoc] pages/windows/where.md $lang:pages.$lang/windows/where.md
13051298
[type: asciidoc] pages/windows/whoami.md $lang:pages.$lang/windows/whoami.md
13061299
[type: asciidoc] pages/windows/xcopy.md $lang:pages.$lang/windows/xcopy.md
1307-

translation-update.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# This script performs the following:
3+
# - Generate configuration file for po4a (can be configured in CONFIGFILE)
4+
# - Generate POT file from pages/<DIRECTORY>/*.md
5+
# - Update PO files in i18n directory with POT file
6+
# - Generate localized pages.XX/<DIRECTORY>/*.md (where XX is the language code)
7+
# - Remove unneeded new lines from generated pages
8+
9+
# Name of the po4a configuration file
10+
CONFIGFILE='po4a.conf'
11+
12+
# List of supported languages
13+
LANGS=(hu)
14+
15+
# Generate po4a.conf file with list of TLDR pages
16+
echo 'Generating configuration file for po4a...'
17+
18+
echo '# WARNING: this file is generated with translation-update.sh' > $CONFIGFILE
19+
echo '# DO NOT modify this file manually!' >> $CONFIGFILE
20+
echo -e >> $CONFIGFILE
21+
echo "[po4a_langs] ${LANGS[*]}" >> $CONFIGFILE
22+
echo '[po4a_paths] i18n/tldr.pot $lang:i18n/tldr.$lang.po' >> $CONFIGFILE
23+
echo -e >> $CONFIGFILE
24+
for FILE in `tree -f -i pages | grep ".md"`
25+
do
26+
echo [type: asciidoc] $FILE \$lang:pages.\$lang/`echo $FILE | cut -d"/" -f 2`/`echo $FILE | cut -d"/" -f 3` >> $CONFIGFILE
27+
done
28+
29+
# Generate POT file, PO files, and pages.XX pages
30+
echo 'Generating POT file and translated TLDR pages...'
31+
po4a -k 0 --msgid-bugs-address 'https://github.com/tldr-pages/tldr/issues' po4a.conf
32+
33+
# Beautify translated TLDR pages (remove unneeded new lines)
34+
for LANG in "${LANGS[@]}"
35+
do
36+
echo "Beautifying TLDR pages ($LANG)..."
37+
for FILE in `tree -f -i pages.$LANG | grep ".md"`
38+
do
39+
sed -i '/[^#|^>|^-|^`].*$/{$!N; s/\n / /g; }' $FILE
40+
done
41+
done

0 commit comments

Comments
 (0)