Skip to content

Commit 57a3571

Browse files
authored
Add apertium translation support (#3)
1 parent dc9e8bb commit 57a3571

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

locales/corrections/it/categories.po

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
msgid "null"
2+
msgstr "Altro"

translation-routing.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
function correct {
4+
FILENAME=$1
5+
DST_DIR=$2
6+
7+
TEMPLATE_FILE="locales/${DST_DIR}/${FILENAME}"
8+
CORRECTIONS_FILE="locales/corrections/${DST_DIR}/${FILENAME}"
9+
10+
if [ ! -f "locales/corrections/${DST_DIR}/${FILENAME}" ]; then
11+
return
12+
fi
13+
14+
pomerge -t ${TEMPLATE_FILE} -i ${CORRECTIONS_FILE} -o ${TEMPLATE_FILE}
15+
}
16+
17+
function translate {
18+
SRC_DIR=$1
19+
FILENAME=$2
20+
LANG_PAIR=$3
21+
DST_DIR=$4
22+
23+
SRC_FILE="locales/${SRC_DIR}/${FILENAME}"
24+
DST_FILE="locales/${DST_DIR}/${FILENAME}"
25+
26+
TRANSLATE_CMD="apertium -- ${LANG_PAIR} -u"
27+
if [ -z "${LANG_PAIR}" ]; then
28+
TRANSLATE_CMD="cat --"
29+
fi
30+
31+
mkdir -p "locales/${DST_DIR}"
32+
cat ${SRC_FILE} | pospell -n - -f -p ${TRANSLATE_CMD} > ${DST_FILE}
33+
34+
correct ${FILENAME} ${DST_DIR}
35+
}
36+
37+
TEMPLATE_DIR="locales/templates"
38+
for TEMPLATE_FILE in "${TEMPLATE_DIR}/*.po"
39+
do
40+
FILENAME=`basename ${TEMPLATE_FILE} ${TEMPLATE_DIR}`
41+
42+
translate "templates" ${FILENAME} "" "en"
43+
translate "templates" ${FILENAME} "en-es" "es"
44+
translate "es" ${FILENAME} "es-fr" "fr"
45+
translate "es" ${FILENAME} "spa-ita" "it"
46+
done

0 commit comments

Comments
 (0)