Skip to content

Commit 2ea6634

Browse files
committed
Update script
1 parent bd639b0 commit 2ea6634

1 file changed

Lines changed: 53 additions & 4 deletions

File tree

tools/extract_template.sh

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
#!/bin/bash
22

3-
# Only strings with domain specified are extracted (use Xt args of keyword param to set number of args needed)
43

5-
xgettext *.php */*.php --copyright-holder='Addressing Development Team' --package-name='GLPI - Addressing plugin' --package-version='3.1.0' -o locales/glpi.pot -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po \
6-
--keyword=_n:1,2,4t --keyword=__s:1,2t --keyword=__:1,2t --keyword=_e:1,2t --keyword=_x:1c,2,3t \
7-
--keyword=_ex:1c,2,3t --keyword=_nx:1c,2,3,5t --keyword=_sx:1c,2,3t
4+
# --- Étape 1 : Extraction des chaînes PHP ---
5+
find . -name '*.php' > php_files.list
86

7+
xgettext --files-from=php_files.list \
8+
--copyright-holder='Addressing Development Team' \
9+
--package-name='Addressing plugin' \
10+
-o locales/glpi.pot \
11+
-L PHP \
12+
--add-comments=TRANS \
13+
--from-code=UTF-8 \
14+
--force-po \
15+
--sort-output \
16+
--keyword=_n:1,2,4t \
17+
--keyword=__s:1,2t \
18+
--keyword=__:1,2t \
19+
--keyword=_e:1,2t \
20+
--keyword=_x:1c,2,3t \
21+
--keyword=_ex:1c,2,3t \
22+
--keyword=_nx:1c,2,3,5t \
23+
--keyword=_sx:1c,2,3t
924

25+
rm php_files.list
1026

27+
# --- Étape 2 : Extraction des chaînes Twig ---
28+
29+
# Append locales from Twig templates
30+
SCRIPT_DIR=$(dirname $0)
31+
WORKING_DIR=$(readlink -f "$SCRIPT_DIR/..") # Script will be executed from "vendor/bin" directory
32+
# Define translate function args
33+
F_ARGS_N="1,2"
34+
F_ARGS__S="1"
35+
F_ARGS__="1"
36+
F_ARGS_X="1c,2"
37+
F_ARGS_SX="1c,2"
38+
F_ARGS_NX="1c,2,3"
39+
F_ARGS_SN="1,2"
40+
41+
for file in $(cd $WORKING_DIR && find -regextype posix-egrep -not -regex $EXCLUDE_REGEX "$SCRIPT_DIR/.." -name "*.twig")
42+
do
43+
# 1. Convert file content to replace "{{ function(.*) }}" by "<?php function(.*); ?>" and extract strings via std input
44+
# 2. Replace "standard input:line_no" by file location in po file comments
45+
contents=`cat $file | sed -r "s|\{\{\s*([a-z0-9_]+\(.*\))\s*\}\}|<?php \1; ?>|gi"`
46+
cat $file | perl -0pe "s/\{\{(.*?)\}\}/<?php \1; ?>/gism" | xgettext - \
47+
-o locales/glpi.pot \
48+
-L PHP \
49+
--add-comments=TRANS \
50+
--from-code=UTF-8 \
51+
--force-po \
52+
--join-existing \
53+
--sort-output \
54+
--keyword=_n:$F_ARGS_N \
55+
--keyword=__:$F_ARGS__ \
56+
--keyword=_x:$F_ARGS_X \
57+
--keyword=_nx:$F_ARGS_NX
58+
sed -i -r "s|standard input:([0-9]+)|`echo $file | sed "s|./||"`:\1|g" locales/glpi.pot
59+
done

0 commit comments

Comments
 (0)