1
1
#! /bin/bash
2
2
3
- # ansi color codes
4
3
RED=' \033[0;31m'
5
4
GREEN=' \033[0;32m'
6
5
YELLOW=' \033[0;33m'
7
6
BLUE=' \033[0;34m'
8
7
MAGENTA=' \033[0;35m'
9
8
CYAN=' \033[0;36m'
10
- NC=' \033[0m' # no color
9
+ NC=' \033[0m'
11
10
12
- # mapping from latin letters to klingon pIqaD code points
13
11
declare -A klingon_map=(
14
12
[" a" ]=$' \uF8D0'
15
13
[" b" ]=$' \uF8D1'
@@ -42,32 +40,24 @@ declare -A klingon_map=(
42
40
[" '" ]=$' \uF8E9'
43
41
)
44
42
45
- # english to klingon word dictionary
46
43
declare -A klingon_dictionary=(
47
- # greetings
48
44
[" hello" ]=" nuqneH"
49
45
[" goodbye" ]=" Qapla'"
50
46
[" hi" ]=" nuqneH"
51
47
[" greetings" ]=" nuqneH"
52
-
53
- # pronouns
54
48
[" i" ]=" jIH"
55
49
[" you" ]=" SoH"
56
50
[" we" ]=" maH"
57
51
[" they" ]=" naDev"
58
52
[" he" ]=" ghaH"
59
53
[" she" ]=" ghaH"
60
54
[" it" ]=" ghaH"
61
-
62
- # common phrases
63
55
[" yes" ]=" HIja'"
64
56
[" no" ]=" ghobe'"
65
57
[" please" ]=" qa'plu'"
66
58
[" thank" ]=" qatlho'"
67
59
[" thanks" ]=" qatlho'"
68
60
[" sorry" ]=" jIQoch"
69
-
70
- # nouns
71
61
[" friend" ]=" jup"
72
62
[" enemy" ]=" jagh"
73
63
[" battle" ]=" veS"
@@ -84,37 +74,28 @@ declare -A klingon_dictionary=(
84
74
[" weaponry" ]=" puqpu'"
85
75
[" sword" ]=" QIch"
86
76
[" blood" ]=" beq"
87
-
88
- # verbs
89
77
[" attack" ]=" batlh"
90
78
[" fight" ]=" batlh"
91
79
[" love" ]=" bang"
92
80
[" hate" ]=" QInvam"
93
81
[" run" ]=" vItlhutlh"
94
82
[" speak" ]=" tlhIngan Hol"
95
-
96
- # adjectives
97
83
[" strong" ]=" vItlhutlh"
98
84
[" brave" ]=" batlh"
99
85
[" quick" ]=" pagh"
100
86
[" swift" ]=" pagh"
101
-
102
- # others
103
87
[" money" ]=" tlhegh"
104
88
[" food" ]=" choq"
105
89
[" leader" ]=" Qun"
106
90
[" king" ]=" raS"
107
91
[" queen" ]=" raS Qun"
108
- # add more words as desired
109
92
)
110
93
111
- # function to translate english to klingon word-by-word
112
94
translate_to_klingon () {
113
95
local sentence=(" $@ " )
114
96
local klingon_sentence=()
115
97
local word translated_word
116
98
117
- # simple pluralization: append 'pu'' for people or 'mey' for objects
118
99
pluralize () {
119
100
case " $1 " in
120
101
jup|jagh|veS|batlh|tlhIngan|wo\' |Duj|DujDaq|Hov|Hegh|ngaD|puq|puqpu\' |QIch|beq|bang|QInvam|vItlhutlh|tlhIngan\ Hol|choq|Qun|raS|raS\ Qun)
@@ -126,9 +107,7 @@ translate_to_klingon() {
126
107
esac
127
108
}
128
109
129
- # iterate over each word
130
110
for word in " ${sentence[@]} " ; do
131
- # handle plural words
132
111
if [[ " $word " == * " s" ]]; then
133
112
base_word=" ${word% s} "
134
113
if [ " ${klingon_dictionary[$base_word]+_} " ]; then
@@ -138,36 +117,25 @@ translate_to_klingon() {
138
117
fi
139
118
fi
140
119
141
- # translate word if exists in dictionary
142
120
if [ " ${klingon_dictionary[$word]+_} " ]; then
143
121
klingon_sentence+=(" ${klingon_dictionary[$word]} " )
144
122
else
145
123
klingon_sentence+=(" $word " )
146
124
fi
147
125
done
148
126
149
- # implement basic Object-Verb-Subject (OVS) word order
150
- # this is a naive implementation and works for simple sentences
151
- # example: "I attack enemy" -> "enemy attack I"
152
-
153
- # identify positions of subject, verb, object
154
- # for simplicity, assume sentences are in "Subject Verb Object" format
155
- # and reorder them to "Object Verb Subject"
156
-
157
127
local subject=" "
158
128
local verb=" "
159
129
local object=" "
160
130
local reordered_sentence=()
161
131
162
- # find subject (pronouns or known subjects)
163
132
for idx in " ${! klingon_sentence[@]} " ; do
164
133
local w=" ${klingon_sentence[$idx]} "
165
134
if [[ " $w " == " jIH" || " $w " == " SoH" || " $w " == " maH" || " $w " == " naDev" || " $w " == " ghaH" ]]; then
166
135
subject=" $w "
167
136
fi
168
137
done
169
138
170
- # find verb (from a set of known verbs)
171
139
declare -A verbs
172
140
verbs=( [" batlh" ]=1 [" bang" ]=1 [" QInvam" ]=1 [" vItlhutlh" ]=1 [" tlhIngan Hol" ]=1 )
173
141
@@ -178,34 +146,28 @@ translate_to_klingon() {
178
146
fi
179
147
done
180
148
181
- # find object (remaining words)
182
149
for w in " ${klingon_sentence[@]} " ; do
183
150
if [[ " $w " != " $subject " && " $w " != " $verb " ]]; then
184
151
object=" $w "
185
152
fi
186
153
done
187
154
188
- # reorder to Object Verb Subject
189
155
if [[ -n " $object " && -n " $verb " && -n " $subject " ]]; then
190
156
reordered_sentence=(" $object " " $verb " " $subject " )
191
157
else
192
- # if cannot determine, keep original order
193
158
reordered_sentence=(" ${klingon_sentence[@]} " )
194
159
fi
195
160
196
- # join the reordered sentence into a single string
197
161
echo " ${reordered_sentence[@]} "
198
162
}
199
163
200
- # function to convert translated Klingon words to pIqaD glyphs
201
164
convert_to_piqaD () {
202
165
local translated_text=" $1 "
203
166
local output_text=" "
204
167
local i=0
205
168
local length=${# translated_text}
206
169
207
170
while [ $i -lt $length ]; do
208
- # handle multicharacter symbols
209
171
if [ " ${translated_text: $i : 3} " == " tlh" ]; then
210
172
output_text+=" ${klingon_map["tlh"]} "
211
173
i=$(( i+ 3 ))
@@ -219,7 +181,7 @@ convert_to_piqaD() {
219
181
output_text+=" ${klingon_map["ng"]} "
220
182
i=$(( i+ 2 ))
221
183
elif [ " ${translated_text: $i : 3} " == " pu'" ]; then
222
- output_text+=" ${klingon_map["'"]} " # represent plural marker as apostrophe
184
+ output_text+=" ${klingon_map["'"]} "
223
185
i=$(( i+ 3 ))
224
186
elif [ " ${translated_text: $i : 1} " == " '" ]; then
225
187
output_text+=" ${klingon_map["'"]} "
@@ -229,7 +191,6 @@ convert_to_piqaD() {
229
191
if [ " ${klingon_map[$char]+_} " ]; then
230
192
output_text+=" ${klingon_map[$char]} "
231
193
else
232
- # for characters not in the mapping, add them as is
233
194
output_text+=" $char "
234
195
fi
235
196
i=$(( i+ 1 ))
@@ -239,34 +200,24 @@ convert_to_piqaD() {
239
200
echo -e " $output_text "
240
201
}
241
202
242
- # main Loop
243
203
while true ; do
244
- # Read user input
245
204
echo -e " ${YELLOW} Enter text (or type 'exit' to quit):${NC} "
246
205
read -p " " input_text
247
206
248
- # exit if user types 'exit' or an empty line
249
207
if [ -z " $input_text " ] || [ " $input_text " == " exit" ]; then
250
208
echo -e " ${GREEN} Qapla'! (Success!)${NC} "
251
209
break
252
210
fi
253
211
254
- # convert input text to lower case
255
212
input_text=$( echo " $input_text " | tr ' [:upper:]' ' [:lower:]' )
256
213
257
- # split input into words
258
214
IFS=' ' read -r -a words <<< " $input_text"
259
215
260
- # translate words to Klingon
261
216
translated_sentence=$( translate_to_klingon " ${words[@]} " )
262
217
263
- # convert translated sentence to pIqaD glyphs
264
218
piqad_text=$( convert_to_piqaD " $translated_sentence " )
265
219
266
- # output the converted text
267
- # echo -e "${BLUE}English:${NC} $input_text"
268
- # echo -e "${MAGENTA}Klingon:${NC} $translated_sentence"
269
220
echo -e " ${CYAN} pIqaD:${NC} "
270
221
echo -e " $piqad_text "
271
- echo " " # add an empty line for better readability
222
+ echo " "
272
223
done
0 commit comments