-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeappendix.a.sh
executable file
·1898 lines (1880 loc) · 120 KB
/
makeappendix.a.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Written by Jeffrey Scott Flesher
#
# This script makes a webpage for a Galactic Calculation
#
declare TheLastUpdate; TheLastUpdate="14 January 2020";
#
# Arguments 1 2 3 4 5 6
# Run Script File with "Sun Size" "Livable Planet Size" "Number of Trinary Engines" "Radius of Galaxy" "Full File Name: appendix.a.xhtml" "Nth"
#
# ./makeappendix.a.sh "864575.9" "7926.2109" "333" "241828072282107.5071453596951" "appendix.a.xhtml" 66
#
# Localize: time ./makeappendix.a.sh -l
# Run Test ./makeappendix.a.sh -t
# Do set Localize Sizes ./makeappendix.a.sh -p
# find . -iname "makeappendix.x.mo" -exec rename makeappendix.x.mo makeappendix.a.mo '{}' \;
# Delete ? in shell?check below
# shell?check -x makeappendix.a.sh
#
# find . -iname "*makeappendix.a.mo*" -exec rename makeappendix.a.mo makeappendix.a.mo '{}' \;
trap "echo Exited!; exit;" SIGINT SIGTERM
#
echo; clear;
#
# FIXME Localize all Prompts
###############################################################################
declare -i ThisPrintNth; ThisPrintNth=1; # Print nth Track to reduce page size: 1=True
declare -i MyTrackNth; MyTrackNth="${6}"; # 1=Every Track, 2=Every other, 3=Every 3rd, so on
declare -i DoOnlineCheck; DoOnlineCheck=0; # 1=Check Online Status of this Page Link
declare -i TheLocalizedFilesSafe; TheLocalizedFilesSafe=1; # 1=Safe: will not overwrite Localized files
declare -i ThisLocalizeAll; ThisLocalizeAll=1; # 1=True Localize all Files, this can get up to 8 Hours.
declare -i UseFreeGoogleTrans; UseFreeGoogleTrans=1; # 1=True Google Translation cost money
declare UserExternalDomainLink; UserExternalDomainLink="LightWizzard.com"; # Change for your use. TrinaryUniversity.org
declare UserBaseName; UserBaseName="trinary-universe"; # Change for your use.
declare TheAuthor; TheAuthor="Jeffrey Scott Flesher"; # Author Name
###############################################################################
declare TheFullScriptPath; TheFullScriptPath="$(dirname "$(readlink -f "${0}")")"; # No Ending /
declare -i ThisRunTest; ThisRunTest=0; #
declare -i ThisSimulateTrans; ThisSimulateTrans=0; # 1=True will Simulate trans for localizing
declare -a ThisProgress=( "-" "\\" "|" "/" ); #
declare -i ThisProgression=0; #
declare -a LocalizedID; LocalizedID=(); # Localize ID for po file
declare -a LocalizedMSG; LocalizedMSG=(); # Localize MSG for po file
declare -a LocalizedComment; LocalizedComment=(); # Localize Comment for po file
# Where do I put these files in Misc
declare TheLocalizedBaseFolderName; TheLocalizedBaseFolderName="localized"; # No slash at end
declare TheLocalizedPathFolderName; TheLocalizedPathFolderName="locale"; # No slash at end
declare TheLocalizedPath; TheLocalizedPath="${TheFullScriptPath}/${TheLocalizedBaseFolderName}/${TheLocalizedPathFolderName}/";
declare TheLocalizedDetailsFolder; TheLocalizedDetailsFolder="details"; # No slash at end
declare TheLocalizedDetailsPath; TheLocalizedDetailsPath="${TheFullScriptPath}/${TheLocalizedBaseFolderName}/${TheLocalizedDetailsFolder}/";
declare TheDefaultLanguage; TheDefaultLanguage="en"; # I wrote this in English so this is a constant
declare ThisLanguage; ThisLanguage="${TheDefaultLanguage}"; # This is set per language file when making Pages
declare TheLocalizedFile; TheLocalizedFile="makeappendix.a"; # I use this throughout this script
declare -i ThisRunLocalizer; ThisRunLocalizer=0; # 1=True set by -l
# Multilingual Langage File Path -> from above: declare -r ${TheFullScriptPath}/${TheMiscFolderName}/${TheLocalizedPathFolderName}/localized"
export TEXTDOMAINDIR="${TheLocalizedPath}";
# Multilingual Langage File Name -> from above: declare TheLocalizedFile="makeappendix.a"
export TEXTDOMAIN="${TheLocalizedFile}";
declare -a TheLocalizeLanguageList; TheLocalizeLanguageList=(); #
# TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="en"; # 1. Do not activate the default language
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="de"; # 2. German
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="fr"; # 3. French
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ja"; # 4. Japanese
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="zh-cn"; # 5. Chinese Simplified
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="zh-tw"; # 6. Chinese Traditional
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ar"; # 7. Arabic
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="es"; # 8. Spanish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ca"; # 9. Catalan
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="da"; # 10. Danish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="nl"; # 11. Dutch
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="tl"; # 12. Filipino
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="fi"; # 13. Finnish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="gl"; # 14. Galician
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="el"; # 15. Greek
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="haw"; # 16. Hawaiian
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="he"; # 17. Hebrew
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="hi"; # 18. Hindi
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="hu"; # 19. Hungarian
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="id"; # 20. Indonesian
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ga"; # 21. Irish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="it"; # 22. Italian
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ko"; # 23. Korean
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ku"; # 24. Kurdish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="pl"; # 25. Polish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="pt"; # 26. Portuguese
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="ru"; # 27. Russian
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="gd"; # 28. Scots Gaelic
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="sw"; # 29. Swahili
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="sv"; # 30. Swedish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="th"; # 31. Thai
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="tr"; # 32. Turkish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="vi"; # 33. Vietnamese
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="yi"; # 34. Yiddish
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="cy"; # 35. Welsh
TheLocalizeLanguageList[$((${#TheLocalizeLanguageList[@]}))]="zu"; # 36. Zulu
# if you want all of them, it will take a month to translate them for free
# TheLocalizeLanguageList=(af ak ar as ast be bg bn-bd bn-in br bs ca cs csb cy da de el en-gb en-us en-za eo es-ar es-cl es-es es-mx et eu fa ff fi fr fy-nl ga-ie gd gl gu-in he hi-in hr hu hy-am id is it ja kk km kn ko ku lg lij lt lv mai mk ml mr nb-no nl nn-no nso or pa-in pl pt-br pt-pt rm ro ru si sk sl son sq sr sv-se ta ta-lk te th tr uk vi zh-cn zh-tw zu);
###############################################################################
declare -i DoBomb; DoBomb=0;
declare -i DosetLocalizeSizes; DosetLocalizeSizes=0;
declare -i DoHelp; DoHelp=0;
# Check Argument Count
if [[ $# -eq 0 ]]; then
DoHelp=1;
elif [[ $# -eq 1 ]]; then
if [ "${1}" == "-l" ]; then
ThisRunLocalizer=1;
elif [ "${1}" == "-p" ]; then
DosetLocalizeSizes=1;
elif [ "${1}" == "-t" ]; then
echo "Test";
ThisRunTest=1;
elif [ "${1}" == "-h" ] || [ "${1}" == "--help" ]; then
DoHelp=1;
else
DoBomb=1;
fi
elif [[ $# -ne 6 ]]; then
DoBomb=1;
fi
###############################################################################
cleanText()
{
if [ $# -ne 1 ]; then echo "LOCALIZE_WRONG_ARGS_PASSED_TO ${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
[[ -z ${1} ]] && { return 1; }
local cleanThis; cleanThis="${1}";
# ' ' '
# html | numeric | hex
# ‘ | ‘ | ‘ // for the left/beginning single-quote and
# ’ | ’ | ’ // for the right/ending single-quote
# ’ for apostrophe and right single quote
# ‘ for left single quote.
# < <
# > >
# " "
# & &
# ' '
# cleanThis="<It's>";
#
# cleanThis="${cleanThis/\'/\'}"; # messes up editor
# shellcheck disable=SC2001
cleanThis="$( echo "${cleanThis}" | sed "s/\'/'/g" )"; # Fix Apostrophe '
# shellcheck disable=SC2001
cleanThis="$( echo "${cleanThis}" | sed 's/\"//g' )"; # Remove quotes
echo "${cleanThis}";
}
###############################################################################
uncleanText()
{
if [ $# -ne 1 ]; then echo "LOCALIZE_WRONG_ARGS_PASSED_TO ${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
[[ -z ${1} ]] && { return 1; }
local cleanThis; cleanThis="${1}";
# shellcheck disable=SC2001
cleanThis="$( echo "${cleanThis}" | sed "s/'/\'/g" )"; # Fix Apostrophe '
echo "${cleanThis}";
}
###############################################################################
declare -i ThisTotalCharacters; ThisTotalCharacters=0;
declare -i ThisTotalWords; ThisTotalWords=0;
setCharacterWordCount()
{
# Test Number of arguments else die
[[ $# -ne 1 ]] && { print_error "LOCALIZE_WRONG_ARGS_PASSED_TO" "Usage: ${FUNCNAME[0]}() 'Status' 'Progress'"; pause_function "$(basename "${BASH_SOURCE[0]}") -> ${FUNCNAME[0]}() : ${LINENO[0]} > ${FUNCNAME[1]}()"; return 1; }
local myTextString; myTextString="${1}";
local ThisOldIFS; ThisOldIFS="$IFS";
local -a thisWordsCount; thisWordsCount=();
local -i thisWC; thisWC=0;
if [ -n "${myTextString-}" ]; then
if [ "${thisWC}" -eq 1 ]; then
ThisTotalWords+=$( echo "${myTextString}" | wc -w );
else
#
IFS=$" ";
# shellcheck disable=SC2206
thisWordsCount=( ${myTextString} );
ThisTotalWords+=${#thisWordsCount[@]};
fi
#
ThisTotalCharacters+=${#myTextString};
fi
#
IFS="$ThisOldIFS";
}
# END setCharacterWordCount
###############################################################################
# 1: myPrintThis: 1 = Print this to screen
#
setLocalizeSizes()
{
# Test Number of arguments else die
[[ $# -ne 1 ]] && { print_error "LOCALIZE_WRONG_ARGS_PASSED_TO" "Usage: ${FUNCNAME[0]}() 'Status' 'Progress'"; pause_function "$(basename "${BASH_SOURCE[0]}") -> ${FUNCNAME[0]}() : ${LINENO[0]} > ${FUNCNAME[1]}()"; return 1; }
local -i myPrintThis; myPrintThis="${1}";
local thisPOfile;
local myLine;
local ThisOldIFS; ThisOldIFS="$IFS";
local -i thisLocalStringIndex; thisLocalStringIndex=0;
local thisLocalString;
#
thisPOfile="${TheLocalizedPath}${TheDefaultLanguage}/${TheDefaultLanguage}.po";
if [ "${myPrintThis}" -eq 1 ]; then
printInColor "Working on ${TheDefaultLanguage}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
printInColor "${thisPOfile}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
if [ -f "${thisPOfile}" ]; then
while IFS='' read -r line || [[ -n "${line}" ]]; do
if [ "${myPrintThis}" -eq 1 ]; then
echo -en "\b${ThisProgress[$((ThisProgression++))]}"; [[ ${ThisProgression} -ge 3 ]] && ThisProgression=0;
fi
if [[ -n "${line}" ]] && [[ "${line:0:1}" != "#" ]]; then
if [ "${line:0:5}" == "msgid" ]; then
myLine="$( cleanText "${line:6}" )";
#echo "msgid: |${myLine}|"
LocalizedID[$((${#LocalizedID[@]}))]="${myLine}";
elif [ "${line:0:6}" == "msgstr" ]; then
myLine="$( cleanText "${line:7}" )";
#echo "msgid: |${myLine}|"
LocalizedMSG[$((${#LocalizedMSG[@]}))]="${myLine}";
setCharacterWordCount "${myLine}";
fi
fi # END if [[ -n "${line}" ]] && [[ "${line:0:1}" != "#" ]]; then
done < "${thisPOfile}"
fi # END if [ -f "${thisPOfile}" ]; then
for thisLocalStringIndex in "${!LocalizedID[@]}"; do
#echo "${LocalizedMSG[${thisLocalStringIndex}]}"
gettext -s "${LocalizedID[${thisLocalStringIndex}]}"
done # END for thisLocalStringIndex in "${!LocalizedID[@]}"; do
printInColor "" "${ColorBgBlack}" "${ColorFgWhite}" 1;
printInColor "Total Number of Words: ${ThisTotalWords}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
printInColor "Total Number of Characters: ${ThisTotalCharacters}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
else
ThisTotalWords=0;
ThisTotalCharacters=0;
for thisLocalString in "${LocalizedMSG[@]}"; do
setCharacterWordCount "${thisLocalString}";
done # END for thisLocalString in "${LocalizedID[@]}"; do
fi
#
#
IFS="$ThisOldIFS";
}
# END setLocalizeSizes
###############################################################################
# All Functions
#
showDetails() { echo ""; echo " Last Update: ${TheLastUpdate}"; echo ""; cat "${TheLocalizedDetailsPath}/readme.${TheDefaultLanguage}.txt"; }
showUsage() { showDetails; printf "%s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n\n" "showUsage: ${0}" "Arguments Localize -l, -h,--help or 6 Arguments" "1: [Sun Size in Miles in Diameter]" "2: [Livable Planet Size in Miles in Diameter]" "3: [Number of Trinary Engines]" "4: [Radius of Galaxy in Miles]" "5: [Full File Name: ${MyOutputFileName}]" "6: [Print Nth Track]" 1>&2; }
# END details
# humanize 123456 = 123,456
# FIXME Localize
humanize() { printf "%'.f" "${1}"; }
# roundit 3 1.123456 = 1.123
roundit() { LC_ALL=C /usr/bin/printf "%.*f" "${1}" "${2}"; }
isOnline() { if ! ping -w5 -c3 "${1}" > /dev/null 2>&1; then sleep 3; if ! ping -w5 -c3 "${1}" > /dev/null 2>&1; then return 1; else return 0; fi else return 0; fi }
# -------------------------------------
declare STACK;
function get_stack()
{
if [ $# -ne 1 ]; then echo "LOCALIZE_WRONG_ARGS_PASSED_TO ${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
STACK="";
local i message; message="${1:-""}"
local stack_size; stack_size=${#FUNCNAME[@]};
local func;
local linen;
local src;
# to avoid noise we start with 1 to skip the get_stack function
for (( i=1; i<stack_size; i++ )); do
func="${FUNCNAME[$i]}"
[ x"$func" = x ] && func=MAIN;
linen="${BASH_LINENO[$(( i - 1 ))]}"
src="${BASH_SOURCE[$i]}"
[ x"$src" = x ] && src=non_file_source;
STACK+=$'\n\t'"at: ${func} ${src} ${linen}"
done
STACK="${message}${STACK}";
}
# No way to test Path
# Below need to be set Manually
declare -i ThisTmHP; ThisTmHP=0; # Trinary Marker High Precision: 0 = False, 1 = true
declare -i ThisAutoDate; ThisAutoDate=0; # If 1 = True, 0 = Manual Entry below
# Below are auto set
declare ThisDateThisDay; ThisDateThisDay="14"; # Change this String for Day
declare -i ThisDateThisMonth; ThisDateThisMonth=1; # Change this Number for Month
declare ThisDateThisYear; ThisDateThisYear="2020"; # Change this String for Year
if [ "${ThisAutoDate}" -eq 1 ]; then
ThisDateThisDay="$(printf %02d "$(date +%d)")";
ThisDateThisMonth="$(printf %02d "$(date +%m)")";
ThisDateThisYear="$(printf %02d "$(date +%Y)")";
fi
declare -a ThisDateMonthArray; ThisDateMonthArray=("January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December");
declare ThisDateUpdated; ThisDateUpdated="${ThisDateThisDay} ${ThisDateMonthArray[((${ThisDateThisMonth} - 1))]} ${ThisDateThisYear}"; # Last Update
declare ThisDateChanged; ThisDateChanged="${ThisDateThisYear}-$(printf %02d "${ThisDateThisMonth}")-${ThisDateThisDay}"; # Change Date
# Variables
# Trinary Marker 137: Some Scientist like to use a Higher Precision
declare ThisTM; ThisTM=0.0; # Trinary Marker:
if [ "${ThisTmHP}" -eq 1 ]; then
ThisTM="$(bc <<< "scale=13;1 / 137.03599913")"; # 1/137.03599913 = 0.00729735256683 Note: This has Major Issues
else
ThisTM="$(bc <<< "scale=13;1 / 137")"; # 1/137 = 0.0072992700729 Note: Default Behavior because it works
fi
# Track Number
declare -i ThisTrackNumber; ThisTrackNumber=0; # Counter for loop
# 3 Rings of Magnetic Force Fields
declare ThisRingPlanetSecond; ThisRingPlanetSecond=0.001; # This is based on the Second Ring of the Earth
# 1. Sun Size in miles in diameter
declare MySunSize;
if [ "${ThisRunLocalizer}" -eq 1 ] || [ "${ThisRunTest}" -eq 1 ] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ]; then
MySunSize="864575.9";
else
MySunSize="${1}"; # Default: Our Sun: 864575.9
fi
# 2. Livable Planet Size in miles in diameter
declare MyLivePlanetSize;
if [ "${ThisRunLocalizer}" -eq 1 ] || [ "${ThisRunTest}" -eq 1 ] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ]; then
MyLivePlanetSize="7926.2109";
else
MyLivePlanetSize="${2}"; # Default: Earth 7926.2109
fi
# 3. Trinary Engines
declare -i MyTrinaryEngines;
if [ "${ThisRunLocalizer}" -eq 1 ] || [ "${ThisRunTest}" -eq 1 ] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ]; then
MyTrinaryEngines="-333";
else
MyTrinaryEngines="((-${3}))"; # Default Starting number Trinary Engines: -333; Negative for Dark Stars.
fi
declare -i ThisTrackEngines; ThisTrackEngines="${MyTrinaryEngines}"; # Trinary Engines
# 4. Track Radius
declare MyGalaxyRadius;
if [ "${ThisRunLocalizer}" -eq 1 ] || [ "${ThisRunTest}" -eq 1 ] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ]; then
MyGalaxyRadius="241828072282107.5071453596951";
else
MyGalaxyRadius="${4}"; # based on the size of the Light in parsecs: 241828072282107.5071453596951
fi
# 5. Full Path, File Name and Extension
declare -x MyOutputFileName;
if [ "${ThisRunLocalizer}" -eq 1 ] || [ "${ThisRunTest}" -eq 1 ] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ]; then
MyOutputFileName="appendix.a.xhtml";
else
MyOutputFileName="${5}"; # Default: "appendix.a.xhtml"
fi
# Total number of Tracks: 666 * 2 + 1 since its 0 based: 1333
declare -i ThisTotalTracks; ThisTotalTracks="(( ((${MyTrinaryEngines#-} * 2) * 2) + 1 ))";
# Atmospheric Pressure Index acts as a Dampener for the Core Frequency causing it to expand at a known Rate based on its Size.
# Livable Planet Ring Frequency: ThisAP is based on Planet Earth, I do not make this an Arguments because I have no way of getting this data
# Torr is a unit of pressure based on an absolute scale defined as 1/760
declare ThisLpDensity; ThisLpDensity=73.120284; # Newtons Constant for Earths Atmospheric Density based on Torr
declare ThisAP; ThisAP="$(roundit 7 "$(bc <<< "scale=9;${ThisLpDensity} * (1/760)")")"; # Earth=0.0962109
declare ThisLpRingFreq; ThisLpRingFreq="$(bc <<< "scale=13;(${MyLivePlanetSize} * ${ThisRingPlanetSecond}) - ${ThisAP}")"; # 7926.2109 * 0.001 = 7.9262109 - ThisAP = 7.830 Hz
# Error Rate
# Based on how much Precession a Sun can have based on its Size Ratio derived by measuring a Top of various sizes
declare ThisCpRate; ThisCpRate=324.540503; # Constant Precession Rate: Constant in Newtons work.
declare ThisPrate; ThisPrate="$(bc <<< "scale=0;${MySunSize}/${ThisCpRate}")"; # Precession Rate: Sun: 10,656 / 4 = 2664
# 2664
declare ThisMaxErrorRate; ThisMaxErrorRate="${ThisPrate}"; # Precession: you must remove the speed required to over come it.
declare ThisMinErrorRate; ThisMinErrorRate=0; # I adjusted the date as to not need this, but its still required.
declare ThisPI; ThisPI=3.14159265359; # PI: to use a higher Precession would require recalculate of baseline.
# Iteration Ranges
declare ThisMaxIteration; # ThisMaxIteration: The longest an Iteration can be
# ThisTM="$(bc <<< "scale=13;1 / 137")";
# MySunSize="864575.9";
# echo "$(bc <<< "scale=0;(${MySunSize} * ${ThisTM}) / 3")";
# 2103
ThisMaxIteration="$(bc <<< "scale=0;(${MySunSize} * ${ThisTM}) / 3")"; # (Diameter in miles) x 1/137 / (3 Phase) = Max Iteration in years
declare ThisAveIteration; # ThisAveIteration: Based on Suns Magnetic Polarity Reversals
ThisAveIteration="$(bc <<< "scale=0;${ThisMaxIteration} - 91")"; # Sun changes polarity 10-11 (0 - 9) times a Century: 100 - 9 = 91
# 2103-42=2061, what we want is 2103-91=2012, do not confuse End of Time with Average Iteration.
declare ThisMinIteration; # ThisMinIteration: Based on Max Min of Magnetic Fields from Newton
ThisMinIteration="$(bc <<< "scale=0;${ThisMaxIteration} - 1104")"; # I hard coded date so I did not need Error Rate: Adds down to 6
# 999
declare ThisMaxSpeed; ThisMaxSpeed=0.0; # ThisMaxSpeed: As it begins decent into Galactic Plane
declare ThisMinSpeed; ThisMinSpeed=0.0; # ThisMinSpeed: At its Maximum Amplitude
# Note that there are two ways to get this value; below and using the Livable Planets Properties
#
# List of all Ring Force Fields
#
# Ring-Galaxy-1 = 0.000000000000001
# Ring-Galaxy-2 = 0.00000000000001
# Ring-Galaxy-3 = 0.0000000000001
#
# Ring-Sun-1 = 0.00001
# Ring-Sun-2 = 0.0001
# Ring-Sun-3 = 0.001
#
# Ring-Planet-1 = 0.0001
# Ring-Planet-2 = 0.001
# Ring-Planet-3 = 0.01
#
# Earth for example: Orbital distance in Miles around Sun = 584,000,000 / (365 Days * 24 Hours) = 66,666.666 MPH * 0.0001 = 6.6666666 Hz
# So this is a Double Verification Process; proving that this Math actually works both ways which is Magic proving God Designed this.
declare ThisLpFrequency; ThisLpFrequency=0.0; # Frequency: $ThisMaxSpeed * $ThisRingSunFirst = Frequency of Livable Planet
declare ThisRingSunFirst; ThisRingSunFirst=0.00001; # This is based on the First Ring of the Sun
declare ThisOrbitDist; ThisOrbitDist=0; # Orbital Distance in Miles around the Track.
declare ThisTracFreqMultiplier; ThisTracFreqMultiplier=.0000000000001; # Track Frequency Multiplier based on Galaxy Ring of Power
declare ThisTrackFreq; ThisTrackFreq=0.0; # Track Frequency: .0000000000001 * ${ThisMinSpeed#-}
declare ThisTabSpace; ThisTabSpace=" "; # Tab Space
declare ThisTableClass; ThisTableClass='class="normal_center"'; # These are CSS class names used to create the Table
declare ThisRowClass; ThisRowClass='class="oddlist"'; # These are CSS class names used to create the Table
declare ThisCellClass; ThisCellClass='class="normal_center"'; # These are CSS class names used to create the Table
declare ThisCellClassCenter; ThisCellClassCenter='class="normal_center"'; # These are CSS class names used to create the Table
declare ThisCellRightClass; ThisCellRightClass='class="normal_right"'; # These are CSS class names used to create the Table
declare -i ThisCurNth; ThisCurNth=0; # Used to iterate
declare -i ThisPrintThat; ThisPrintThat=1; # Used to iterate
declare -i DoNotSkipThis;
if [ "${ThisRunLocalizer}" -eq 1 ] || [ "${ThisRunTest}" -eq 1 ] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ]; then
DoNotSkipThis="666";
else
DoNotSkipThis="$((${3}*2))"; # To print Track 666 or Life Track
fi
declare -i ThisPrintedLines; ThisPrintedLines=0; # Number of Printed lines
declare -a ThisTextArray; ThisTextArray=(); # Array of Text to Print to Screen and (X)HTML File Format
declare -a ThisTextIDArray; ThisTextIDArray=(); # Array of Text to Print to Screen and (X)HTML File Format
declare -a ThisTextLinesArray; ThisTextLinesArray=(); # Array of Text to Print to Screen in one line
declare ThisDefinition; ThisDefinition=""; # Used to print Definitions
declare ThisTemp; ThisTemp=""; # Used to convert strings
#
# *************************************************************************** #
# 1: Status
# 2: Progress
# printProgress "Running" "total" "myPercent";
# ---------------------------------------
declare -x TermScreenAfter; TermScreenAfter="\033[0J"; # Move to location
declare -x TermLineBefore; TermLineBefore="\033[1K"; # Erase Current Line
#declare -x TermLineAfter; TermLineAfter="\033[0K"; # Erase Current Line
declare -x TermUp; TermUp="\033[1A"; # Move up 1 Line
declare -x TermUpCount; TermUpCount=2; #
declare -x TermMessages; TermMessages="\n"; #
declare -x TermProgress; TermProgress=""; #
#
# *********************************# tput Background
declare -a ColorsBG; ColorsBG=();
declare -i ColorBgBlack; ColorBgBlack=0;
ColorsBG["${ColorBgBlack}"]="$(tput setab 0)"; # 0: Black ${ColorsBG["${ColorBgBlack}"]}
declare -i ColorBgRed; ColorBgRed=1;
ColorsBG["${ColorBgRed}"]="$(tput setab 1)"; # 1: Red
declare -i ColorBgGreen; ColorBgGreen=2;
ColorsBG["${ColorBgGreen}"]="$(tput setab 2)" # 2: Green
declare -i ColorBgYellow; ColorBgYellow=3;
ColorsBG["${ColorBgYellow}"]="$(tput setab 3)" # 3: Yellow
declare -i ColorBgBlue; ColorBgBlue=4;
ColorsBG["${ColorBgBlue}"]="$(tput setab 4)" # 4: Blue
declare -i ColorBgMagenta; ColorBgMagenta=5;
ColorsBG["${ColorBgMagenta}"]="$(tput setab 5)" # 5: Magenta
declare -i ColorBgCyan; ColorBgCyan=6;
ColorsBG["${ColorBgCyan}"]="$(tput setab 6)" # 6: Cyan
declare -i ColorBgWhite; ColorBgWhite=7;
ColorsBG["${ColorBgWhite}"]="$(tput setab 7)" # 7: White
declare -i ColorBgDefault; ColorBgDefault=9;
ColorsBG["${ColorBgDefault}"]="$(tput setab 9)" # 9: Default
#
# ******************************** # tput Foreground
declare -a ColorsFG; ColorsFG=();
declare -i ColorFgBlack; ColorFgBlack=0;
ColorsFG["${ColorFgBlack}"]="$(tput setaf 0)"; # 0: Black ${ColorsFG["${ColorFgBlack}"]}
declare -i ColorFgRed; ColorFgRed=1;
ColorsFG["${ColorFgRed}"]="$(tput setaf 1)" # 1: Red
declare -i ColorFgLightRed; ColorFgLightRed=161;
ColorsFG["${ColorFgLightRed}"]="$(tput setaf 161)" # 161: Light Red
declare -i ColorFgGreen; ColorFgGreen=2;
ColorsFG["${ColorFgGreen}"]="$(tput setaf 2)" # 2: Green
declare -i ColorFgLightGreen; ColorFgLightGreen=19;
ColorsFG["${ColorFgLightGreen}"]="$(tput setaf 19)" # 19: Light Green
declare -i ColorFgYellow; ColorFgYellow=3;
ColorsFG["${ColorFgYellow}"]="$(tput setaf 3)" # 3: Yellow
declare -i ColorFgLightYellow; ColorFgLightYellow=11;
ColorsFG["${ColorFgLightYellow}"]="$(tput setaf 11)" # 11: Light Yellow
declare -i ColorFgBlue; ColorFgBlue=4;
ColorsFG["${ColorFgBlue}"]="$(tput setaf 4)" # 4: Blue
declare -i ColorFgLightBlue; ColorFgLightBlue=12;
ColorsFG["${ColorFgLightBlue}"]="$(tput setaf 12)" # 12: Light Blue
declare -i ColorFgMagenta; ColorFgMagenta=5;
ColorsFG["${ColorFgMagenta}"]="$(tput setaf 5)" # 5: Magenta
declare -i ColorFgLightMagenta; ColorFgLightMagenta=13;
ColorsFG["${ColorFgLightMagenta}"]="$(tput setaf 13)" # 13: Light Magenta
declare -i ColorFgCyan; ColorFgCyan=6;
ColorsFG["${ColorFgCyan}"]="$(tput setaf 6)" # 6: Cyan
declare -i ColorFgLightCyan; ColorFgLightCyan=14;
ColorsFG["${ColorFgLightCyan}"]="$(tput setaf 14)" # 14: Light Cyan
declare -i ColorFgWhite; ColorFgWhite=7;
ColorsFG["${ColorFgWhite}"]="$(tput setaf 7)" # 7: White
declare -i ColorFgLightWhite; ColorFgLightWhite=15;
ColorsFG["${ColorFgLightWhite}"]="$(tput setaf 15)" # 15: Light White
declare -i ColorFgDefault; ColorFgDefault=9;
ColorsFG["${ColorFgDefault}"]="$(tput setaf 9)" # 9: Default
#
declare -x T_Reset; # Reset
# shellcheck disable=SC2034
T_Reset="$(tput sgr0)";
declare -x T_Bold; # T_Bold
# shellcheck disable=SC2034
T_Bold="$(tput bold)";
declare -x T_Dim; # T_Dim
# shellcheck disable=SC2034
T_Dim="$(tput dim)";
declare -x T_Blink; # T_Blink
# shellcheck disable=SC2034
T_Blink="$(tput blink)";
declare -x T_Begin_Underline; # Begin Underline
# shellcheck disable=SC2034
T_Begin_Underline="$(tput smul)";
declare -x T_End_Underline; # End Underline
# shellcheck disable=SC2034
T_End_Underline="$(tput rmul)";
declare -x T_Reverse; # Reverse
# shellcheck disable=SC2034
T_Reverse="$(tput rev)";
declare -x T_Begin_Standout; # Begin Standout
# shellcheck disable=SC2034
T_Begin_Standout="$(tput smso)";
declare -x T_End_Standout; # End Standout
# shellcheck disable=SC2034
T_End_Standout="$(tput rmso)";
#
declare -x T_Clear_EOL; # Clear to End of Line
# shellcheck disable=SC2034
T_Clear_EOL="$(tput el)";
declare -x T_Clear_BOL; # Clear to Beginning of Line
# shellcheck disable=SC2034
T_Clear_BOL="$(tput el1)";
#
if [ "${DoBomb}" -eq 1 ] || [ "${DoHelp}" -eq 1 ]; then
showUsage; exit 1;
fi
#
if [ "${DosetLocalizeSizes}" -eq 1 ]; then
echo "Print all Localized Files";
setLocalizeSizes 1;
exit 0;
fi
# #############################################################################
# Check input arguments
# Arguments 1 2 3 4 5 6
# Run Script File with "Sun Size" "Livable Planet Size" "Number of Trinary Engines" "Radius of Galaxy" "Full File Name: appendix.a.xhtml" "Nth"
# ./makeappendix.a.sh "864575.9" "7926.2109" "333" "241828072282107.5071453596951" "appendix.a.xhtml" 66
if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] && [ "${DoHelp}" -eq 0 ] && [ "${DoBomb}" -eq 0 ]; then
re='^[+-]?[0-9]+([.][0-9]+)?$'
# Sun Size
if ! [[ "${1}" =~ $re ]] ; then
echo "Input 1 (Sun Size: 864575.9): Not a number";
showUsage; exit 1;
fi
# Livable Planet Size
if ! [[ "${2}" =~ $re ]] ; then
echo "Input 2 (Livable Planet Size: 7926.2109): Not a number";
showUsage; exit 1;
fi
# Radius of Galaxy
if ! [[ "${4}" =~ $re ]] ; then
echo "Input 4 (Radius of Galaxy: 241828072282107.5071453596951): Not a number";
showUsage; exit 1;
fi
# Number of Trinary Engines
re='^[0-9]+$'
if ! [[ "${3}" =~ $re ]] ; then
echo "Input 3 (Number of Trinary Engines: 333): Not a number";
showUsage; exit 1;
fi
# Nth Number
if ! [[ "${6}" =~ $re ]] ; then
echo "Input 6 (Number of Nth Lines to Skip Printing): Not a number";
showUsage; exit 1;
fi
# File Name: Lower Case, Alphanumeric, with; - _ .
re='^[a-z0-9\._-]+(\.[a-z0-9_-]+)?$'
if ! [[ "${5}" =~ $re ]] ; then
echo "Input 5 (File Name: ${MyOutputFileName}) Only Alphanumeric, dot (.), underscore (_) and dash (-) are allowed.";
showUsage; exit 1;
fi
fi # END if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] || [ "${DoHelp}" -eq 0 ] || [ "${DoBomb}" -eq 0 ]; then
###############################################################################
#
# printInColor "Text to Print to Screen" "${ColorBgBlack}" "${ColorFgWhite}"
#
printInColor()
{
[[ $# -ne 4 ]] && { echo "LOCALIZE_WRONG_ARGS_PASSED_TO Usage: ${FUNCNAME[0]}() 'Text' 'Background Color' 'Foreground Color' $(basename "${BASH_SOURCE[0]}") Line # ${LINENO[0]}"; get_stack "${LINENO[0]}"; echo "${STACK}"; return 1; }
local myText; myText="${1}"; #
local -i myBgColor; myBgColor="${2}"; #
local -i myFgColor; myFgColor="${3}"; #
local -i myNewLine; myNewLine="${4}"; #
#
if [ "${myNewLine}" -eq 1 ]; then
echo -e "${T_Clear_BOL}${T_Reset}${ColorsBG[${myBgColor}]}${ColorsFG[${myFgColor}]}${ThisTabSpace}${T_Bold}${myText}${T_Clear_EOL}";
else
echo -ne "${T_Clear_BOL}${T_Reset}${ColorsBG[${myBgColor}]}${ColorsFG[${myFgColor}]}${ThisTabSpace}${T_Bold}${myText}${T_Clear_EOL}";
fi
}
runPrintTest()
{
printInColor "printInColor Test Black Background with White Foreground" "${ColorBgBlack}" "${ColorFgWhite}" 1;
printInColor "printInColor Test Black Background with White Foreground" "${ColorBgBlack}" "${ColorFgRed}" 1;
printInColor "printInColor Test Black Background with Red Foreground" "${ColorBgBlack}" "${ColorFgLightRed}" 1;
printInColor "printInColor Test Black Background with Light Red Foreground" "${ColorBgBlack}" "${ColorFgWhite}" 1;
printInColor "printInColor Test Black Background with Green Foreground" "${ColorBgBlack}" "${ColorFgGreen}" 1;
printInColor "printInColor Test Black Background with Light Green Foreground" "${ColorBgBlack}" "${ColorFgLightGreen}" 1;
printInColor "printInColor Test Black Background with Yellow Foreground" "${ColorBgBlack}" "${ColorFgYellow}" 1;
printInColor "printInColor Test Black Background with Light Yellow Foreground" "${ColorBgBlack}" "${ColorFgLightYellow}" 1;
printInColor "printInColor Test Black Background with Blue Foreground" "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "printInColor Test Black Background with Light Blue Foreground" "${ColorBgBlack}" "${ColorFgLightBlue}" 1;
printInColor "printInColor Test Black Background with Magenta Foreground" "${ColorBgBlack}" "${ColorFgMagenta}" 1;
printInColor "printInColor Test Black Background with Light Magenta Foreground" "${ColorBgBlack}" "${ColorFgLightMagenta}" 1;
printInColor "printInColor Test Black Background with Cyan Foreground" "${ColorBgBlack}" "${ColorFgCyan}" 1;
printInColor "printInColor Test Black Background with LightCyan Foreground" "${ColorBgBlack}" "${ColorFgLightCyan}" 1;
printInColor "printInColor Test Black Background with Light White Foreground" "${ColorBgBlack}" "${ColorFgLightWhite}" 1;
printInColor "printInColor Test Black Background with Default Foreground" "${ColorBgBlack}" "${ColorFgDefault}" 1;
printInColor "printInColor Test White Background with Black Foreground" "${ColorBgWhite}" "${ColorFgBlack}" 1;
printInColor "printInColor Test White Background with Red Foreground" "${ColorBgWhite}" "${ColorFgRed}" 1;
printInColor "printInColor Test White Background with Light Red Foreground" "${ColorBgWhite}" "${ColorFgLightRed}" 1;
printInColor "printInColor Test White Background with Green Foreground" "${ColorBgWhite}" "${ColorFgGreen}" 1;
printInColor "printInColor Test White Background with Light Green Foreground" "${ColorBgWhite}" "${ColorFgLightGreen}" 1;
printInColor "printInColor Test White Background with Yellow Foreground" "${ColorBgWhite}" "${ColorFgYellow}" 1;
printInColor "printInColor Test White Background with Light Yellow Foreground" "${ColorBgWhite}" "${ColorFgLightYellow}" 1;
printInColor "printInColor Test White Background with Blue Foreground" "${ColorBgWhite}" "${ColorFgBlue}" 1;
printInColor "printInColor Test White Background with Light Blue Foreground" "${ColorBgWhite}" "${ColorFgLightBlue}" 1;
printInColor "printInColor Test White Background with Magenta Foreground" "${ColorBgWhite}" "${ColorFgMagenta}" 1;
printInColor "printInColor Test White Background with Light Magenta Foreground" "${ColorBgWhite}" "${ColorFgLightMagenta}" 1;
printInColor "printInColor Test White Background with Cyan Foreground" "${ColorBgWhite}" "${ColorFgCyan}" 1;
printInColor "printInColor Test White Background with Light Cyan Foreground" "${ColorBgWhite}" "${ColorFgLightCyan}" 1;
printInColor "printInColor Test White Background with Default Foreground" "${ColorBgWhite}" "${ColorFgDefault}" 1;
printInColor "printInColor Reset to Black Background with White Foreground" "${ColorBgBlack}" "${ColorFgWhite}" 1;
}
###############################################################################
#
printProgress()
{
# Test Number of arguments else die
[[ $# -ne 3 ]] && { print_error "LOCALIZE_WRONG_ARGS_PASSED_TO" "Usage: ${FUNCNAME[0]}() 'Status' 'Progress'"; pause_function "$(basename "${BASH_SOURCE[0]}") -> ${FUNCNAME[0]}() : ${LINENO[0]} > ${FUNCNAME[1]}()"; return 1; }
local myMessage; myMessage="${1}"; # First time must be the Message, after that its blank
local -i myProgressTotal; myProgressTotal="${2}"; # Total
local -i myProgressPercent; myProgressPercent="${3}"; # Current Number
#
local thisStatus; thisStatus="[ ] 0%";
local thisPercentage;
# ---------------------------------------
# 1: Command to echo
# 2: Count
termReset()
{
[[ $# -ne 2 ]] && { print_error "LOCALIZE_WRONG_ARGS_PASSED_TO" "Usage: ${FUNCNAME[0]}() 'Count' 'Terminal Code UP'"; pause_function "$(basename "${BASH_SOURCE[0]}") -> ${FUNCNAME[0]}() : ${LINENO[0]} > ${FUNCNAME[1]}()"; return 1; }
local myCount; myCount="${2}"
while (( myCount )); do
echo -en "${1}";
(( myCount-- ));
done
}
# ---------------------------------------
termUpdateStatus()
{
# Move Up Number of Lines
termReset "${TermUp}" "${TermUpCount}";
# Move to location, Erase Line, and back up
echo -en "${T_Clear_BOL}${T_Reset}${ColorsBG["${ColorBgBlack}"]}${ColorsBG["${ColorFgGreen}"]}${T_Bold}${TermLineBefore}" "${TermScreenAfter}" "\r";
#echo -en "${T_Clear_BOL}${TermLineBefore}" "${TermScreenAfter}" "\r";
# Print Message
echo -en "${TermMessages}";
# Print Progress
echo -e "${T_Clear_BOL}${ThisTabSpace}${TermProgress}${T_Clear_EOL}";
}
# ---------------------------------------
# 1: Message
termAddMessage()
{
[[ $# -ne 1 ]] && { print_error "LOCALIZE_WRONG_ARGS_PASSED_TO" "Usage: ${FUNCNAME[0]}() 'Message'"; pause_function "$(basename "${BASH_SOURCE[0]}") -> ${FUNCNAME[0]}() : ${LINENO[0]} > ${FUNCNAME[1]}()"; return 1; }
TermMessages+="${ThisTabSpace}${1}\n";
(( TermUpCount++ ));
}
# ---------------------------------------
# 1: Progress
termSetProgress()
{
[[ $# -ne 1 ]] && { print_error "LOCALIZE_WRONG_ARGS_PASSED_TO" "Usage: ${FUNCNAME[0]}() 'Progress'"; pause_function "$(basename "${BASH_SOURCE[0]}") -> ${FUNCNAME[0]}() : ${LINENO[0]} > ${FUNCNAME[1]}()"; return 1; }
TermProgress="${1}";
termUpdateStatus;
}
# ---------------------------------------
# If not empty add a message
if [[ -n "${myMessage}" ]]; then
TermUpCount=2;
TermMessages="\n";
TermProgress="";
termAddMessage "${myMessage}";
termReset "\n" ${TermUpCount};
fi
# Make sure you do not divide by 0
if [ "${myProgressPercent}" -gt 0 ] && [ "${myProgressTotal}" -gt 0 ]; then
thisCalPercentage="$(bc <<< "scale=1;(${myProgressPercent} / ${myProgressTotal}) * 100")";
thisPercentage=${thisCalPercentage%.*}
else
thisPercentage=0;
fi
#
if [ "${thisPercentage}" -gt 1 ] && [ "${thisPercentage}" -lt 11 ]; then # 10%
thisStatus="[# ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 9 ] && [ "${thisPercentage}" -lt 21 ]; then # 20%
thisStatus="[## ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 19 ] && [ "${thisPercentage}" -lt 31 ]; then # 30%
thisStatus="[### ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 39 ] && [ "${thisPercentage}" -lt 41 ]; then # 40%
thisStatus="[#### ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 49 ] && [ "${thisPercentage}" -lt 51 ]; then # 50%
thisStatus="[##### ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 59 ] && [ "${thisPercentage}" -lt 61 ]; then # 60%
thisStatus="[###### ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 69 ] && [ "${thisPercentage}" -lt 71 ]; then # 70%
thisStatus="[####### ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 79 ] && [ "${thisPercentage}" -lt 81 ]; then # 80%
thisStatus="[######## ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 89 ] && [ "${thisPercentage}" -lt 91 ]; then # 90%
thisStatus="[######### ] ${thisPercentage}%";
elif [ "${thisPercentage}" -gt 99 ] && [ "${thisPercentage}" -lt 101 ]; then # 100%
thisStatus="[##########] ${thisPercentage}%";
fi
#
termSetProgress "${thisStatus}";
#
}
# END printProgress
###############################################################################
# 1. Time in Seconds
sleepFor()
{
local -i mySleepTotal; mySleepTotal="${1}";
local -i thisSleepPercent; thisSleepPercent=0;
printProgress "Sleeping for ${1} seconds..." "${mySleepTotal}" "${thisSleepPercent}";
for (( thisSleepPercent=0; thisSleepPercent<mySleepTotal; thisSleepPercent++ )); do
printProgress "" "${mySleepTotal}" "${thisSleepPercent}";
sleep 1;
done
printProgress "" "${mySleepTotal}" "${mySleepTotal}";
printInColor "Waking up..." "${ColorBgBlack}" "${ColorFgGreen}" 1;
}
###############################################################################
# use -no-auto to disable autocorrect
localizeIt()
{
[[ ${ThisRunLocalizer} -eq 0 ]] || [[ "${ThisRunTest}" -eq 1 ]] || [ "${DoHelp}" -eq 1 ] || [ "${DoBomb}" -eq 1 ] && return 0;
#
local -i thisSetDebug; thisSetDebug=0; # 0=No, 1=Yes
local -i totalLocalized; totalLocalized="${#LocalizedID[@]}";
local -i totalLanguages; totalLanguages="${#TheLocalizeLanguageList[@]}";
local -i thisLanguagesIndex; thisLanguagesIndex=0;
local -i thisLocalStringIndex; thisLocalStringIndex=0;
local -i toggleThis; toggleThis=0;
local -i sleepTime; sleepTime=0;
local -i perLineSleep; perLineSleep=0;
local -i perFileSleep; perFileSleep=0;
local thisPOfile; thisPOfile="po";
local thisMOfile; thisMOfile="mo";
local thisTrans; thisTrans="mo-po";
local -i doTrans; doTrans=1;
#
if [ "${ThisSimulateTrans}" -eq 0 ]; then
if [ "${UseFreeGoogleTrans}" -eq 1 ]; then
# perLineSleep=66; # 60 is 1 Minute, for Free they might cut you off if you make more request then that in 10 Minutes
# perFileSleep=3666; # 3600 is 1 Hour, for Free this is a very limited amount of characters per hour
perLineSleep=33; # 60 is 1 Minute, for Free they might cut you off if you make more request then that in 10 Minutes
perFileSleep=333; # 3600 is 1 Hour, for Free, this is a very limited amount of characters per hour
else
perLineSleep=1; # No delay means Hammer on the Server
perFileSleep=6;
fi
else
perLineSleep=1;
perFileSleep=1;
fi
if [ ${thisSetDebug} -eq 1 ]; then set -x; fi # Turn On Debug mode
# http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/PO-Files.html
#
#
mkdir -p "${TheLocalizedPath}${TheDefaultLanguage}/LC_MESSAGES/";
#
echo "# Trinary Galactic Table Translation File" > "${TheLocalizedPath}${TheDefaultLanguage}/${TheDefaultLanguage}.po"; # Overwrite
echo "" >> "${TheLocalizedPath}${TheDefaultLanguage}/${TheDefaultLanguage}.po"; # Appends
#
printInColor "Localized total=${totalLocalized}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
#
#
for thisLanguagesIndex in "${!LocalizedID[@]}"; do
#echo -en "\b${ThisProgress[$((ThisProgression++))]}"; [[ ${ThisProgression} -ge 3 ]] && ThisProgression=0;
{
echo "# msgcomment: ${LocalizedComment[$thisLanguagesIndex]}"
echo "msgid \"${LocalizedID[$thisLanguagesIndex]}\""
echo "msgstr \"${LocalizedMSG[$thisLanguagesIndex]}\""
echo ""
} >> "${TheLocalizedPath}${TheDefaultLanguage}/${TheDefaultLanguage}.po";
done
# make mo file
msgfmt -o "${TheLocalizedPath}${TheDefaultLanguage}/LC_MESSAGES/${TheLocalizedFile}.mo" "${TheLocalizedPath}${TheDefaultLanguage}/${TheDefaultLanguage}.po";
#
setLocalizeSizes 0; # set Character and Word Count if we need it
printInColor "Total Number of Words: ${ThisTotalWords}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
printInColor "Total Number of Characters: ${ThisTotalCharacters}" "${ColorBgBlack}" "${ColorFgWhite}" 1;
#
if [ "${ThisLocalizeAll}" -eq 1 ]; then
if hash "trans" 2>/dev/null; then
#
for thisLanguagesIndex in "${!TheLocalizeLanguageList[@]}"; do
doTrans=1;
thisPOfile="${TheLocalizedPath}${TheLocalizeLanguageList[${thisLanguagesIndex}]}/${TheLocalizeLanguageList[${thisLanguagesIndex}]}.po";
thisMOfile="${TheLocalizedPath}${TheLocalizeLanguageList[${thisLanguagesIndex}]}/LC_MESSAGES/${TheLocalizedFile}.mo";
if [ "${TheLocalizedFilesSafe}" -eq 1 ]; then
if [ -f "${thisPOfile}" ]; then
if [ -f "${thisMOfile}" ]; then
doTrans=0;
fi
fi
fi # END if [ "${TheLocalizedFilesSafe}" -eq 1 ]; then
#
if [ "${doTrans}" -eq 1 ]; then
mkdir -p "${TheLocalizedPath}${TheLocalizeLanguageList[${thisLanguagesIndex}]}";
mkdir -p "${TheLocalizedPath}${TheLocalizeLanguageList[${thisLanguagesIndex}]}/LC_MESSAGES/";
echo "# Trinary Galactic Table Translation File" > "${thisPOfile}"; # Overwrite
echo "" >> "${thisPOfile}"; # Appends
for thisLocalStringIndex in "${!LocalizedID[@]}"; do
printInColor "Working on ${thisLanguagesIndex} of ${totalLanguages}: Localizating ${TheLocalizeLanguageList[${thisLanguagesIndex}]}: ${thisLocalStringIndex} of ${totalLocalized}: ${LocalizedID[${thisLocalStringIndex}]}" "${ColorBgBlack}" "${ColorFgBlue}" 1;
if [ "${ThisSimulateTrans}" -eq 0 ]; then
thisTrans="$( trans -no-autocorrect -no-warn -b -s en -t "${TheLocalizeLanguageList[${thisLanguagesIndex}]}" \""${LocalizedMSG[$thisLocalStringIndex]}"\" )";
else
thisTrans="${TheLocalizeLanguageList[${thisLanguagesIndex}]}: Simulation of trans";
fi
thisTrans="$(echo "${thisTrans}" | tr -d '\"' )"; # Remove all quotes, sometimes end quotes is missing or odd number
# we do not want to count quotes as not empty
if [ "${#thisTrans}" -eq 0 ]; then
thisTrans="\"${LocalizedMSG[$thisLocalStringIndex]}\""; # Must be in Quotes
else
thisTrans="\"${thisTrans}\""; # Now add them back, this makes sure the quotes are right
fi
#
printInColor "Trans=|${thisTrans}|" "${ColorBgBlack}" "${ColorFgYellow}" 1;
# enclosure for writing files
{
echo "# msgcomment: ${LocalizedComment[${thisLocalStringIndex}]}"
echo "msgid \"${LocalizedID[$thisLocalStringIndex]}\""
echo "msgstr ${thisTrans}"
echo ""
} >> "${thisPOfile}";
#
if [ "${UseFreeGoogleTrans}" -eq 1 ]; then
# I do not want to pound on the Server to translate this, they have kick me off; not sure how long to wait, work in progress...
# I have 118 lines so far, so how long do you want to wait, this is per Language,
# I have 36 Languages selected; that is 4248 * how many seconds you chose,
# at 6 x 4248 = 25,488 seconds / 60 = 424.8 Minutes, / 60 = 7.08 Hours
# Google is now Paid only, but you can get a few Free ones,
# at over 1 per minute, I have about 118 of them, so that is 118 minutes or almost 2 Hours per file
# so adding 2 hours x 118 files = 236 Hours or 9 day
# plus the fact we are only getting 1 file with a 1-hour wait so its more like 9 days and 8 hours to get if for free
# so I need to make a Progress Bar that reflects this
if [ "${ThisSimulateTrans}" -eq 0 ]; then
if [ "${toggleThis}" -eq 0 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 1 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 2 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 3 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 4 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 5 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 6 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 7 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 8 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 9 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 10 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 11 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 12 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
elif [ "${toggleThis}" -eq 13 ]; then
sleepTime=$(( perLineSleep + toggleThis ));
toggleThis=0;
fi
fi # END if [ "${ThisSimulateTrans}" -eq 0 ]; then
sleepFor "${sleepTime}";
(( toggleThis++ ))
fi # END if [ "${UseFreeGoogleTrans}" -eq 1 ]; then
done # END for thisLocalStringIndex in "${!LocalizedID[@]}"; do
#
if [ "${ThisSimulateTrans}" -eq 0 ]; then
msgfmt -o "${thisMOfile}" "${thisPOfile}";
fi
#
if [ "${UseFreeGoogleTrans}" -eq 1 ]; then
sleepFor "${perFileSleep}"; # 3666 seconds (over an hour per file supported) is an eternity for a Computer, but they limit you per hour, no fails required
# this will take 36 x 3,666 = 131,976 or 36.66 Hours to complete, try to push it and you will have trans rejections or untrans strings
fi # END if [ "${useFreeGoogleTrans}" -eq 1 ]; then
fi # END if [ "${doTrans}" -eq 1 ]; then
done # END for thisLanguagesIndex in "${!TheLocalizeLanguageList[@]}"; do
else # if hash "trans" 2>/dev/null; then
printInColor "trans not installed" "${ColorBgBlack}" "${ColorFgRed}" 1;
printInColor "This Bash Script is not only Localized," "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "it is self Localizing, it will look up the Translation for every Language you chose," "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "and create the File for you." "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "https://github.com/soimort/translate-shell" "${ColorBgBlack}" "${ColorFgYellow}" 1;
printInColor "You must copy file to Path, you cannot access it from inside another script otherwise." "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "This downloads the latest file from git" "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "wget git.io/trans" "${ColorBgBlack}" "${ColorFgYellow}" 1;
printInColor "this changes Permissions so you can execute it" "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "chmod +x ./trans" "${ColorBgBlack}" "${ColorFgYellow}" 1;
printInColor "You can move it to any Folder in your Path, I just use bin, because its the right place to put it." "${ColorBgBlack}" "${ColorFgBlue}" 1;
printInColor "sudo mv trans /usr/bin/" "${ColorBgBlack}" "${ColorFgYellow}" 1;
fi # END if hash "trans" 2>/dev/null; then
fi # END if [ "${ThisLocalizeAll}" -eq 1 ]; then
if [ "${thisSetDebug}" -eq 1 ]; then set +x; fi # turn OFF debug mode
}
# END localizeIt
###############################################################################
#
# setLocalized "ID" "Text" "Comment";
setLocalized()
{
if [ $# -ne 3 ]; then echo "LOCALIZE_WRONG_ARGS_PASSED_TO ${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
local thisID; thisID="${1}";
local thisText; thisText="${2}";
local thisComment; thisComment="${3}";
[[ -z ${thisID} ]] && { echo "LOCALIZE_WRONG_ARGS_NULL thisID"; return 1; }
[[ -z ${thisText} ]] && { echo "LOCALIZE_WRONG_ARGS_NULL thisText"; return 1; }
[[ -z ${thisComment} ]] && { echo "LOCALIZE_WRONG_ARGS_NULL thisComment"; get_stack "${FUNCNAME[0]}"; echo "${STACK}" return 1; }
#
ThisTextIDArray[$((${#ThisTextIDArray[@]}))]="${thisID}";
ThisTextArray[$((${#ThisTextArray[@]}))]="${thisText}";
LocalizedID[${#LocalizedID[*]}]="${thisID}";
LocalizedMSG[${#LocalizedMSG[*]}]="${thisText}";
LocalizedComment[${#LocalizedComment[*]}]="${thisComment}";
}
###############################################################################
print2File()
{
if [ $# -ne 2 ]; then echo "LOCALIZE_WRONG_ARGS_PASSED_TO ${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
[[ -z ${2} ]] && { return 1; }
if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] && [ "${DoHelp}" -eq 0 ] && [ "${DoBomb}" -eq 0 ]; then
uncleanText "${1}" >> "${2}";
fi
}
###############################################################################
#
# 1: Array
# 2: Localized Name
printDefinition()
{
if [ $# -ne 2 ]; then printf "%s %s \n" "LOCALIZE_WRONG_ARGS_PASSED_TO" "${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
[[ -z ${1} ]] && { return 1; }
local -n thisArray="$1";
local thisString;
[[ -z ${2} ]] && { printf "%s %s \n" "LOCALIZE_NAME_NOT_SPECIFIED" "${FUNCNAME[0]}(): ${2} @ $(basename "${BASH_SOURCE[0]}") Line # ${LINENO[0]}"; exit 1; }
# Start Definitions
print2File "${ThisTabSpace}" "${MyOutputFileName}";
print2File "${ThisTabSpace}"'<dt><span class="text_code">'"$( gettext -s "${2}" )"'</span></dt>' "${MyOutputFileName}";
if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] && [ "${DoHelp}" -eq 0 ] && [ "${DoBomb}" -eq 0 ]; then
printInColor "$( gettext -s "${2}" )" "${ColorBgBlack}" "${ColorFgCyan}" 1;
fi
print2File "${ThisTabSpace}<dd class=\"small_dd\">" "${MyOutputFileName}";
for thisText in "${thisArray[@]}"; do
thisString="$( cleanText "${thisText}" )";
thisString="$( gettext -s "${thisString}" )";
if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] && [ "${DoHelp}" -eq 0 ] && [ "${DoBomb}" -eq 0 ]; then
print2File "${ThisTabSpace}${ThisTabSpace}${thisString}<br />" "${MyOutputFileName}";
printInColor "$( gettext -s "${thisString}" )" "${ColorBgBlack}" "${ColorFgCyan}" 1;
fi
done
print2File "${ThisTabSpace}</dd>" "${MyOutputFileName}";
if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] && [ "${DoHelp}" -eq 0 ] && [ "${DoBomb}" -eq 0 ]; then
printInColor "" "${ColorBgBlack}" "${ColorFgWhite}" 1;
fi
ThisTextArray=();
ThisTextLinesArray=();
}
###############################################################################
#
printParagraph()
{
if [ $# -ne 1 ]; then printf "%s %s \n" "LOCALIZE_WRONG_ARGS_PASSED_TO" "${FUNCNAME[0]}() @ $(basename "${BASH_SOURCE[0]}") : Line # ${LINENO[0]}"; exit 1; fi
[[ -z ${1} ]] && { return 1; }
local -n thisArray="${1}";
local thisString;
print2File "" "${MyOutputFileName}";
print2File '<p class="small">' "${MyOutputFileName}";
for thisText in "${thisArray[@]}"; do
thisString="$( cleanText "${thisText}" )";
thisString="$( gettext -s "${thisString}" )"
if [ "${ThisRunLocalizer}" -eq 0 ] && [ "${ThisRunTest}" -eq 0 ] && [ "${DoHelp}" -eq 0 ] && [ "${DoBomb}" -eq 0 ]; then
print2File "${ThisTabSpace}${thisString}<br />" "${MyOutputFileName}";
printInColor "$( gettext -s "${thisString}" )" "${ColorBgBlack}" "${ColorFgMagenta}" 1;
fi
done
print2File "</p>" "${MyOutputFileName}";
ThisTextArray=();