-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_translation_wizard.sh
More file actions
executable file
·164 lines (138 loc) · 8.33 KB
/
create_translation_wizard.sh
File metadata and controls
executable file
·164 lines (138 loc) · 8.33 KB
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
#! /bin/bash
# Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 nerdopolis (or n3rdopolis) <bluescreen_avenger@verzion.net>
#
# This file is part of LinuxRCD.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#get the location of the directory that this script is in
folderlocation="$( dirname $(readlink -f "$0" ) )"
linuxrcdfolderlocaton="$(echo $folderlocation/linuxrcd_files)"
export BUILDLOCATION=~/LRCD_Build_Files
#program dialog is needed to prompt user
which dialog > /dev/null
dialoginstalled=$?
if [ $dialoginstalled = 1 ]
then
echo "package 'dialog' not installed. please install the package 'dialog' by using your package manager, as it is needed."
exit 1
fi
#Create a directory name where temporary files will be stored
TranslationCacheFile="/tmp/translationgeneration$(date +%s)"
#introduce the translator to this script
echo "This is the translation wizard for LinuxRCD. It scans the files for translatable strings and thier descriptions so that you can add a language translation for LinuxRCD."
echo "This script must be in the root of the LinuxRCD build script folder. (you should see a folder called linuxrcd_files in the same folder as this script)"
echo "This script will make changes to the following folders and files.
File: "$TranslationCacheFile"
Folder: "$linuxrcdfolderlocaton"
MAKE SURE this script will not overwrite anything before pressing enter to continue!!!!..."
read a
echo "searching for translatable files in $linuxrcdfolderlocaton"
#if there is no linuxrcd_files folder in the same folder as this script, exit.
if [ ! -d "$linuxrcdfolderlocaton" ]
then
echo "No 'linuxrcd_files' folder found in the same folder as this script. exiting..."
exit 1
fi
#ask the name of the language the user is making
echo "Enter the name of the language you are making a translation for, and hit enter"
languagename=$(dialog --no-cancel --stdout --inputbox "Enter Language Name" 20 999 )
#if no language was entered, exit
if [ -z $languagename ]
then
echo "no language entered. exiting..."
exit 1
fi
#make the language folder.
mkdir -p "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename"
#find all files in the linux_rcd files that have the string in them to show themselves as translatable.
find "$linuxrcdfolderlocaton" \( -name .svn \) -prune -o -print | grep -v '\.@@@TRANSLATABLE_FOLDERNAME@@@' | while read FILE
do
#If it's a translatable folder
if [[ -d "$FILE" && -f "$FILE/.@@@TRANSLATABLE_FOLDERNAME@@@" ]]
then
#grab the file name of the file being translated
filename="$(echo "$FILE" | rev | awk -F / '{print $1}' | rev )"
#get the linuxrcd relitive path location.
foldername="$(echo "$FILE" | awk -F "$linuxrcdfolderlocaton/" '{print $2}' | awk -F "$filename" '{print $1}' )"
#search the file for if the file name is translatable
cat "$FILE/.@@@TRANSLATABLE_FOLDERNAME@@@" | while read LINE
do
#get the name of the translation string In file string translation loop, its the file name
translationname="$( echo $filename )"
#get the translation descrition in the file, to aid the translator
translationdescription="$( echo $LINE | awk -F"~~~~~~~~~~~" '{ print $1 }' )"
#get the current contents of the translation
oldtranslationtext=$(cat "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/FILEFOLDERNAME" | awk -F"~~~~~~~~~~~" '{ print $1 }' )
#prompt for the new translation, with the old translation in the line.
newtranslationtext="$(dialog --no-cancel --stdout --inputbox "Translating LinuxRCD's $foldername$filename
translation description for string $translationname: $translationdescription" 20 999 "$oldtranslationtext" )"
#make the folder for the translation
mkdir -p "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/"
#create the translation file for the file name
echo "$newtranslationtext~~~~~~~~~~~" > "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/FILEFOLDERNAME"
done
fi
#find if it is translatable by counting the number of the @@@TRANSLATABLE_FILE@@@ string in the file
if [ `grep -c "@@@TRANSLATABLE_FILE@@@" "$FILE"` -eq 0 ]
then
#if none, don't do anything, but it seems that "if" needs to run a command here, otherwise it returns an error...
sleep 0
else
#grab the file name of the file being translated
filename="$(echo "$FILE" | rev | awk -F / '{print $1}' | rev )"
#get the linuxrcd relitive path location.
foldername="$(echo "$FILE" | awk -F "$linuxrcdfolderlocaton/" '{print $2}' | awk -F "$filename" '{print $1}' )"
#search the file for if the file name is translatable
cat "$FILE" | grep @@@TRANSLATABLE_FILENAME@@@ | while read LINE
do
#get the name of the translation string In file string translation loop, its the file name
translationname="$( echo $filename )"
#get the translation descrition in the file, to aid the translator
translationdescription="$( echo $LINE | awk -F"~~~~~~~~~~~" '{ print $2 }' )"
#get the current contents of the translation
oldtranslationtext=$(cat "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/FILEFOLDERNAME" | awk -F"~~~~~~~~~~~" '{ print $1 }' )
#prompt for the new translation, with the old translation in the line.
newtranslationtext="$(dialog --no-cancel --stdout --inputbox "Translating LinuxRCD's $foldername$filename
translation description for string $translationname: $translationdescription" 20 999 "$oldtranslationtext" )"
#make the folder for the translation
mkdir -p "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/"
#create the translation file for the file name
echo "$newtranslationtext~~~~~~~~~~~" > "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/FILEFOLDERNAME"
done
#grab translatable strings from the file
cat "$FILE" | grep @@@TRANSLATABLE_STRING@@@ | while read LINE
do
#get the name of the translation string. This is embeded in the file.
translationname="$( echo $LINE | awk -F"~~~~~~~~~~~" '{ print $2 }' )"
#get the translation description to aid the translator.
translationdescription="$( echo $LINE | awk -F"~~~~~~~~~~~" '{ print $3 }' )"
#get the internal translation options for the LinuxRCD build script
translationoptions="$( echo $LINE | awk -F"~~~~~~~~~~~" '{ print $4 }' )"
#get the current contents of the translation
oldtranslationtext=$(cat "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/TRANSLATION_DATA" | grep "$translationname" | awk -F"~~~~~~~~~~~" '{ print $2 }' )
#prompt for the new translation, with the old translation in the line.
newtranslationtext="$(dialog --no-cancel --stdout --inputbox "Translating LinuxRCD's $foldername$filename
translation description for string $translationname: $translationdescription" 20 999 "$oldtranslationtext" )"
#copy the current translation in a cached location, without the old translation for this string
cat "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/TRANSLATION_DATA" | grep -v "$translationname" > "$TranslationCacheFile"
#put the new translation in the cached file
echo "$translationname~~~~~~~~~~~$newtranslationtext~~~~~~~~~~~$translationoptions" >> "$TranslationCacheFile"
#create the folder for the new translation
mkdir -p "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/"
#move the edited cached file into the correct location so the new translation is applied
mv "$TranslationCacheFile" "$linuxrcdfolderlocaton/usr/share/linuxrcd/translations/$languagename/file_translations/$foldername$filename/TRANSLATION_DATA"
done
rm $TranslationCacheFile
fi
done