forked from igatjens/transifex-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-translations.sh
executable file
·170 lines (133 loc) · 4.34 KB
/
patch-translations.sh
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
#-This is a bash script for use with transifex
#-==============================================================================
#- patch-translations.sh
#-
#- Author : Isaías Gatjens M - Twitter @igatjens
#- Version : v0.2
#- License : Distributed under the terms of GNU GPL version 2 or later
#-
#-
#- notes :
#-==============================================================================
#Obtener la lista de recursos para parchar
LIST_OF_PATCH=$(grep -E -v "^ *#|none" os_translations.conf | sed -e 's/ *//g; s/\t\t*/;/g')
TRANSLATIONS_DIR=translations/
MO_FILES_OS_DIR=/usr/share/locale/
COUNT=1
TOTAL_RESOURCES=$( echo $LIST_OF_PATCH | wc -w)
#Para cada recurso
for i in $LIST_OF_PATCH; do
#statements
#echo $i
DIR_RESOURCES=$TRANSLATIONS_DIR$(echo $i | cut -d ";" -f 1)/
DIR_SYSTEM=$(echo $i | cut -d ";" -f 2)
APP_NAME=$(echo $i | cut -d ";" -f 3)
FIX_APP_NAME=$(echo $i | cut -d ";" -f 4)
echo "==============================================="
#echo $DIR_RESOURCES
#echo $DIR_SYSTEM
echo $APP_NAME $COUNT of $TOTAL_RESOURCES
#echo $FIX_APP_NAME
echo "-----------------------------------------------"
#si la carpeta del recurso existe
if [[ -d $DIR_RESOURCES ]]; then
#statements
cd $DIR_RESOURCES
QM_FILES=$(ls *.qm 2> /dev/null)
MO_FOLDERS=$( ls -d */ 2> /dev/null)
#echo $MO_FOLDERS
#Si el destino no es /usr/share/locale/ entonces parche los archivos .qm
if [[ ! $( echo $DIR_SYSTEM | grep LC_MESSAGES ) ]]; then
#statements
#si la carpeta de la aplicación existe
if [[ -d $DIR_SYSTEM ]]; then
#statements
#si encuentra archivos .qm
if [[ $QM_FILES ]]; then
#statements
for NAME_FILE in $QM_FILES; do
#statements
FIX_NAME_FILE=""
QM_FILES_OS=""
#si hay FIX_APP_NAME aplicar FIX_APP_NAME
if [[ $FIX_APP_NAME ]]; then
#statements
#echo Existe un fix_name
#echo j--- $NAME_FILE
TAIL_NAME_FILE=$( echo $NAME_FILE | sed "s|.*_|_|")
#echo tali $TAIL_NAME_FILE
FIX_NAME_FILE=$FIX_APP_NAME$TAIL_NAME_FILE
#echo full $FIX_NAME_FILE
QM_FILES_OS=$DIR_SYSTEM$FIX_NAME_FILE
else
QM_FILES_OS=$DIR_SYSTEM$NAME_FILE
fi
#Borrar el _en del nombre de archivo
#QM_FILES_OS=$( echo $QM_FILES_OS | sed "s|_en.qm|.qm|" )
#si los archivos .qm existen en el sistema, haga un respaldo
if [[ -f $QM_FILES_OS ]]; then
#statements
echo Backup $QM_FILES_OS"_"$(date +%Y-%m-%d_%H.%M.%S)
sudo mv $QM_FILES_OS $QM_FILES_OS"_"$(date +%Y-%m-%d_%H.%M.%S)
else
echo Notice: The $QM_FILES_OS file does not exists
fi
echo Copy $NAME_FILE → $QM_FILES_OS
sudo cp -u $NAME_FILE $QM_FILES_OS
done
else
echo Notice: .qm files not found in $DIR_RESOURCES
fi
else
echo Error: Folder $DIR_SYSTEM does not exist.
fi
fi
if [[ $MO_FOLDERS ]]; then
#statements
echo -e "\nPatching .mo files"
echo "-----------------------------------------------"
fi
for MO in $MO_FOLDERS; do
#Si existe LC_MESSAGES
if [[ -d $MO/LC_MESSAGES ]]; then
#statements
cd $MO/LC_MESSAGES
MO_FILES=$(ls *.mo 2> /dev/null)
#echo .mo files $MO$MO_FILES
MO_FILE_OS=""
TAIL_NAME_FILE=""
FIX_NAME_FILE=""
#si hay FIX_APP_NAME aplicar FIX_APP_NAME
if [[ $FIX_APP_NAME ]]; then
#statements
TAIL_NAME_FILE=$( echo $MO_FILES | sed "s|.*\.mo|\.mo|")
#echo tali $TAIL_NAME_FILE
FIX_NAME_FILE=$FIX_APP_NAME$TAIL_NAME_FILE
#echo full $FIX_NAME_FILE
MO_FILE_OS=$(echo $MO_FILES_OS_DIR$MO"LC_MESSAGES/"$FIX_NAME_FILE)
else
MO_FILE_OS=$(echo $MO_FILES_OS_DIR$MO"LC_MESSAGES/"$MO_FILES)
fi
#si los archivos .mo existen en el sistema, haga un respaldo
if [[ -f $MO_FILE_OS ]]; then
#statements
echo Backup $MO_FILE_OS"_"$(date +%Y-%m-%d_%H.%M.%S)
sudo mv $MO_FILE_OS $MO_FILE_OS"_"$(date +%Y-%m-%d_%H.%M.%S)
else
echo Notice: The $MO_FILE_OS file does not exists
fi
echo Copy $MO_FILES → $MO_FILE_OS
sudo cp -u $MO_FILES $MO_FILE_OS
cd ../..
else
echo Error: LC_MESSAGES folder not found in $DIR_RESOURCES$MO
fi
done
cd ../..
else
echo Error: Folder $DIR_RESOURCES does not exist.
fi
echo -e "===============================================\n\n"
let COUNT=COUNT+1
done