File: generate_pot.sh

package info (click to toggle)
pcsx2 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 28,424 kB
  • sloc: cpp: 299,797; ansic: 23,973; lisp: 2,689; asm: 908; perl: 852; sh: 789; xml: 116; makefile: 60
file content (124 lines) | stat: -rw-r--r-- 5,069 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh

# PCSX2 - PS2 Emulator for PCs
# Copyright (C) 2002-2014  PCSX2 Dev Team
#
# PCSX2 is free software: you can redistribute it and/or modify it under the terms
# of the GNU Lesser General Public License as published by the Free Software Found-
# ation, either version 3 of the License, or (at your option) any later version.
#
# PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with PCSX2.
# If not, see <http://www.gnu.org/licenses/>.

# This script call xgettext utility to generate some nice pot (translation template) files

set -e

######################################################################
# Script configuration
######################################################################
VERSION=1.6.0
COPYRIGHT="PCSX2 Dev Team"
BUG_MAIL="https://github.com/PCSX2/pcsx2/issues"

GENERAL_OPTION="--sort-by-file --no-wrap --package-name=PCSX2 \
	--package-version=$VERSION --msgid-bugs-address=$BUG_MAIL"


######################################################################
# Build Input file list
######################################################################
[ ! -e pcsx2 ] && echo "pcsx2 directory not present" && exit 1;
[ ! -e common ] && echo "common directory not present" && exit 1;
[ ! -e locales ] && echo "locales directory not present" && exit 1;

# Build a list of all input files
input_files=""
for directory in pcsx2 common
do
    for type in cpp h
    do
        new_input_files=`find $directory -iname "*.${type}" -print0 | xargs -0`
        input_files="$input_files $new_input_files"
    done
done

######################################################################
# Generate the pot
######################################################################
MAIN_POT=locales/templates/pcsx2_Main.pot
MAIN_KEY1=_
MAIN_KEY2=pxL

DEV_KEY1=_d
DEV_KEY2=pxDt

TER_KEY1=_t
TER_KEY2=pxLt
TER_KEY3=pxEt

echo "Generate $MAIN_POT"
xgettext --keyword=$MAIN_KEY1 --keyword=$MAIN_KEY2 --keyword=$DEV_KEY1 --keyword=$DEV_KEY2 \
	--keyword=$TER_KEY1 --keyword=$TER_KEY2 $GENERAL_OPTION --copyright-holder="$COPYRIGHT"  \
	$input_files --output=$MAIN_POT
sed --in-place $MAIN_POT --expression=s/charset=CHARSET/charset=UTF-8/

ICO_POT=locales/templates/pcsx2_Iconized.pot
ICO_KEY1=pxE

echo "Generate $ICO_POT"
xgettext --keyword=$ICO_KEY1 --keyword=$TER_KEY3 $GENERAL_OPTION --copyright-holder="$COPYRIGHT" \
	$input_files --output=$ICO_POT
sed --in-place $ICO_POT --expression=s/charset=CHARSET/charset=UTF-8/

######################################################################
# Add poedit metadata
# It eases poedit for translators
######################################################################
# Metadata example
# "X-Poedit-KeywordsList: pxE_dev;pxDt\n"
# "X-Poedit-SourceCharset: utf-8\n"
# "X-Poedit-Basepath: trunk\\\n"
# "X-Poedit-SearchPath-0: pcsx2\n"
# "X-Poedit-SearchPath-1: common\n"
# Normally "...Content-Transfer-Encoding..." is the end of the header. Use it as anchor to place poedit metadata after
COMMON_META="\"X-Poedit-SourceCharset: utf-8\\\n\"\n\"X-Poedit-Basepath: trunk\\\\\\\\\\\n\"\n\"X-Poedit-SearchPath-0: pcsx2\\\n\"\n\"X-Poedit-SearchPath-1: common\\\n\""
sed --in-place $MAIN_POT --expression=s/'\"Content-Transfer-Encoding: 8bit\\n\"'/"\"Content-Transfer-Encoding: 8bit\\\n\"\n\"X-Poedit-KeywordsList: ${MAIN_KEY1};${MAIN_KEY2};${DEV_KEY1};${DEV_KEY2};${TER_KEY1};${TER_KEY2}\\\n\"\n${COMMON_META}"/
sed --in-place $ICO_POT --expression=s/'\"Content-Transfer-Encoding: 8bit\\n\"'/"\"Content-Transfer-Encoding: 8bit\\\n\"\n\"X-Poedit-KeywordsList: ${ICO_KEY1};${TER_KEY3}\\\n\"\n${COMMON_META}"/

######################################################################
# Automatically align the .po to the new pot file
######################################################################
echo "Update pcsx2_Main.po files"
for po_file in `find ./locales -iname pcsx2_Main.po`
do
    # Note: --previous corrupt po file
    msgmerge --update $po_file $MAIN_POT
done

echo "Update pcsx2_Iconized.po files"
for po_file in `find ./locales -iname pcsx2_Iconized.po`
do
    # Note: --previous corrupt po file
    msgmerge --update $po_file $ICO_POT
done

######################################################################
# Automatically compile po into mo file
######################################################################
echo "Compile po files, result are directly installed on bin/Langs directory"
for po_file in `find ./locales -iname "pcsx2_*.po"`
do
    mo_file=`echo $po_file | sed -e 's/locales/bin\/Langs/' | sed -e 's/\.po/.mo/'`
    mkdir -p `dirname $mo_file`
    msgfmt -o $mo_file $po_file
done

######################################################################
# Clean garbage
######################################################################
find ./locales -iname "pcsx2_*.po~" -exec rm {} \;