script-convertor.blade.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. @extends('layouts.library')
  2. @section('title', __('labels.script_convertor'))
  3. @push('styles')
  4. <style>
  5. .converter-page {
  6. padding: 2rem 0 4rem;
  7. }
  8. .converter-title {
  9. text-align: center;
  10. font-size: 1.5rem;
  11. font-weight: 600;
  12. margin-bottom: 1.5rem;
  13. color: var(--tblr-body-color, #1e293b);
  14. }
  15. .converter-layout {
  16. display: flex;
  17. gap: 1rem;
  18. align-items: stretch;
  19. min-height: 400px;
  20. }
  21. .converter-panel {
  22. flex: 1;
  23. display: flex;
  24. flex-direction: column;
  25. }
  26. .converter-panel label {
  27. font-weight: 500;
  28. margin-bottom: .5rem;
  29. font-size: .875rem;
  30. color: var(--tblr-body-color, #475569);
  31. }
  32. .converter-panel select {
  33. margin-bottom: .75rem;
  34. padding: .5rem .75rem;
  35. border: 1px solid var(--tblr-border-color, #d1d5db);
  36. border-radius: .375rem;
  37. font-size: .875rem;
  38. background: var(--tblr-bg-surface, #fff);
  39. color: var(--tblr-body-color, #1e293b);
  40. }
  41. .converter-panel textarea {
  42. flex: 1;
  43. min-height: 300px;
  44. padding: .75rem;
  45. border: 1px solid var(--tblr-border-color, #d1d5db);
  46. border-radius: .375rem;
  47. font-family: 'Noto Sans', 'Noto Sans CJK SC', 'Noto Sans Myanmar', sans-serif;
  48. font-size: 1rem;
  49. line-height: 1.6;
  50. resize: vertical;
  51. background: var(--tblr-bg-surface, #fff);
  52. color: var(--tblr-body-color, #1e293b);
  53. }
  54. .converter-panel textarea:focus,
  55. .converter-panel select:focus {
  56. outline: none;
  57. border-color: var(--tblr-primary, #0054a6);
  58. box-shadow: 0 0 0 .25rem rgba(0, 84, 166, .1);
  59. }
  60. .converter-middle {
  61. display: flex;
  62. flex-direction: column;
  63. align-items: center;
  64. justify-content: center;
  65. gap: 1rem;
  66. min-width: 120px;
  67. padding: 1rem 0;
  68. }
  69. .converter-middle label {
  70. font-size: .8rem;
  71. font-weight: 500;
  72. text-align: center;
  73. color: var(--tblr-body-color, #475569);
  74. }
  75. .converter-middle select {
  76. padding: .375rem .5rem;
  77. border: 1px solid var(--tblr-border-color, #d1d5db);
  78. border-radius: .375rem;
  79. font-size: .875rem;
  80. background: var(--tblr-bg-surface, #fff);
  81. }
  82. .btn-convert {
  83. display: inline-flex;
  84. align-items: center;
  85. justify-content: center;
  86. padding: .5rem 1.5rem;
  87. font-size: 1.25rem;
  88. font-weight: 600;
  89. border: none;
  90. border-radius: .375rem;
  91. background: var(--tblr-primary, #0054a6);
  92. color: #fff;
  93. cursor: pointer;
  94. transition: background .15s;
  95. }
  96. .btn-convert:hover {
  97. background: var(--tblr-primary-darken, #004080);
  98. }
  99. @media (max-width: 768px) {
  100. .converter-layout {
  101. flex-direction: column;
  102. }
  103. .converter-middle {
  104. flex-direction: row;
  105. justify-content: center;
  106. min-width: unset;
  107. padding: .5rem 0;
  108. }
  109. .converter-panel textarea {
  110. min-height: 200px;
  111. }
  112. }
  113. </style>
  114. @endpush
  115. @section('content')
  116. <div class="page-body">
  117. <div class="container-xl converter-page">
  118. <h1 class="converter-title">{{ __('labels.script_convertor') }}</h1>
  119. <div class="converter-layout">
  120. {{-- Input --}}
  121. <div class="converter-panel">
  122. <label for="inputScript">{{ __('labels.input_script') }}</label>
  123. <select id="inputScript">
  124. <option value="roman">{{ __('labels.script_roman') }}</option>
  125. <option value="sangayana">{{ __('labels.script_sangayana') }}</option>
  126. <option value="sinhala">{{ __('labels.script_sinhala') }}</option>
  127. <option value="myanmar">{{ __('labels.script_myanmar') }}</option>
  128. <option value="tai_tham">{{ __('labels.script_tai_tham') }}</option>
  129. <option value="thai">{{ __('labels.script_thai') }}</option>
  130. <option value="tai_old">{{ __('labels.script_tai_old') }}</option>
  131. </select>
  132. <textarea id="txtInput" placeholder="{{ __('labels.paste_here') }}"></textarea>
  133. </div>
  134. {{-- Middle --}}
  135. <div class="converter-middle">
  136. <div>
  137. <label for="niggahitaSelect">{{ __('labels.niggahita_label') }}</label>
  138. <select id="niggahitaSelect">
  139. <option value="ṃ,Ṃ">ṃ</option>
  140. <option value="ṁ,Ṁ">ṁ</option>
  141. <option value="ŋ,Ŋ">ŋ</option>
  142. </select>
  143. </div>
  144. <button type="button" class="btn-convert" onclick="convert()">→</button>
  145. </div>
  146. {{-- Output --}}
  147. <div class="converter-panel">
  148. <label for="outputScript">{{ __('labels.output_script') }}</label>
  149. <select id="outputScript">
  150. <option value="roman">{{ __('labels.script_roman') }}</option>
  151. <option value="sangayana">{{ __('labels.script_sangayana') }}</option>
  152. <option value="sinhala1">{{ __('labels.script_sinhala_traditional') }}</option>
  153. <option value="sinhala2">{{ __('labels.script_sinhala_modern') }}</option>
  154. <option value="chinese_detail">{{ __('labels.script_chinese_detail') }}</option>
  155. <option value="chinese_simple">{{ __('labels.script_chinese_simple') }}</option>
  156. <option value="chinese_pinyin">{{ __('labels.script_chinese_pinyin') }}</option>
  157. <option value="telugu">{{ __('labels.script_telugu') }}</option>
  158. <option value="myanmar">{{ __('labels.script_myanmar') }}</option>
  159. <option value="tai_tham">{{ __('labels.script_tai_tham') }}</option>
  160. <option value="thai">{{ __('labels.script_thai') }}</option>
  161. </select>
  162. <textarea id="txtOutput" placeholder="{{ __('labels.converted_text') }}" readonly></textarea>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. @endsection
  168. @push('scripts')
  169. <script src="{{ asset('charcode/unicode.js') }}"></script>
  170. <script src="{{ asset('charcode/sinhala.js') }}"></script>
  171. <script src="{{ asset('charcode/myanmar.js') }}"></script>
  172. <script src="{{ asset('charcode/tai_tham.js') }}"></script>
  173. <script src="{{ asset('charcode/thai.js') }}"></script>
  174. <script src="{{ asset('charcode/chinese.js') }}"></script>
  175. <script src="{{ asset('charcode/telugu.js') }}"></script>
  176. <script>
  177. (function () {
  178. function applyMap(text, map) {
  179. for (let i = 0; i < map.length; i++) {
  180. text = text.replace(new RegExp(map[i].id, 'g'), map[i].value);
  181. }
  182. return text;
  183. }
  184. function getNiggahita() {
  185. const val = document.getElementById('niggahitaSelect').value;
  186. const parts = val.split(',');
  187. return { lower: parts[0], upper: parts[1] };
  188. }
  189. function sangayanaToUnicode(text) {
  190. const n = getNiggahita();
  191. text = text.replace(/ïk/g, n.lower + 'k');
  192. text = text.replace(/ïg/g, n.lower + 'g');
  193. text = text.replace(/ü/g, n.lower);
  194. text = text.replace(/§/g, n.lower);
  195. text = text.replace(/ṃ/g, n.lower);
  196. text = text.replace(/ðK/g, n.upper + 'K');
  197. text = text.replace(/ðG/g, n.upper + 'G');
  198. text = text.replace(/ý/g, n.upper);
  199. return applyMap(text, char_sanga_to_unicode);
  200. }
  201. function unicodeToSangayana(text) {
  202. return applyMap(text, char_unicode_to_sanga);
  203. }
  204. function normalizeNiggahita(text) {
  205. const n = getNiggahita();
  206. text = text.replace(/ṅk/g, n.lower + 'k');
  207. text = text.replace(/ṅg/g, n.lower + 'g');
  208. text = text.replace(/ŋk/g, n.lower + 'k');
  209. text = text.replace(/ŋg/g, n.lower + 'g');
  210. text = text.replace(/ŋ/g, n.lower);
  211. text = text.replace(/ṁ/g, n.lower);
  212. text = text.replace(/ṃ/g, n.lower);
  213. text = text.replace(/ṃk/g, 'ṅk');
  214. text = text.replace(/ṁk/g, 'ṅk');
  215. text = text.replace(/ṃg/g, 'ṅg');
  216. text = text.replace(/ṁg/g, 'ṅg');
  217. text = text.replace(/ṄK/g, n.upper + 'K');
  218. text = text.replace(/ṄG/g, n.upper + 'G');
  219. text = text.replace(/ŊK/g, n.upper + 'K');
  220. text = text.replace(/ŊG/g, n.upper + 'G');
  221. text = text.replace(/Ŋ/g, n.upper);
  222. text = text.replace(/Ṁ/g, n.upper);
  223. text = text.replace(/Ṃ/g, n.upper);
  224. text = text.replace(/ṂK/g, 'ṄG');
  225. text = text.replace(/ṀK/g, 'ṄG');
  226. text = text.replace(/ṂG/g, 'ṄG');
  227. text = text.replace(/ṀG/g, 'ṄG');
  228. return text;
  229. }
  230. function toRoman(text, inputType) {
  231. switch (inputType) {
  232. case 'sangayana':
  233. return sangayanaToUnicode(text);
  234. case 'sinhala':
  235. text = applyMap(text, char_si_to_unicode);
  236. return normalizeNiggahita(text);
  237. case 'myanmar':
  238. text = applyMap(text, char_myn_to_roman_1);
  239. return normalizeNiggahita(text);
  240. case 'tai_tham':
  241. text = applyMap(text, char_tai_to_roman);
  242. return normalizeNiggahita(text);
  243. case 'thai':
  244. text = applyMap(text, char_thai_to_roman);
  245. return normalizeNiggahita(text);
  246. case 'tai_old':
  247. text = applyMap(text, char_tai_old_to_r);
  248. return normalizeNiggahita(text);
  249. default:
  250. return normalizeNiggahita(text);
  251. }
  252. }
  253. function fromRoman(text, outputType) {
  254. text = text.toLowerCase();
  255. switch (outputType) {
  256. case 'sangayana':
  257. return unicodeToSangayana(' ' + text);
  258. case 'sinhala1':
  259. return applyMap(text, char_unicode_to_si_c);
  260. case 'sinhala2':
  261. return applyMap(text, char_unicode_to_si_n);
  262. case 'chinese_detail':
  263. text = applyMap(text, char_chinese_pronounce_1);
  264. return normalizeNiggahita(text);
  265. case 'chinese_simple':
  266. text = applyMap(text, char_chinese_pronounce_2);
  267. return normalizeNiggahita(text);
  268. case 'chinese_pinyin':
  269. text = ' ' + text;
  270. text = applyMap(text, char_chinese_pinyin);
  271. text = text.toLowerCase();
  272. return normalizeNiggahita(text);
  273. case 'telugu':
  274. text = applyMap(text, char_unicode_to_telugu);
  275. return normalizeNiggahita(text);
  276. case 'myanmar':
  277. text = applyMap(text, char_roman_to_myn);
  278. return normalizeNiggahita(text);
  279. case 'tai_tham':
  280. text = applyMap(text, char_roman_to_tai);
  281. return normalizeNiggahita(text);
  282. case 'thai':
  283. text = applyMap(text, char_roman_to_thai);
  284. return normalizeNiggahita(text);
  285. default:
  286. return normalizeNiggahita(text);
  287. }
  288. }
  289. window.convert = function () {
  290. const inputType = document.getElementById('inputScript').value;
  291. const outputType = document.getElementById('outputScript').value;
  292. const inputText = document.getElementById('txtInput').value;
  293. const roman = toRoman(inputText, inputType);
  294. const result = fromRoman(roman, outputType);
  295. document.getElementById('txtOutput').value = result;
  296. };
  297. })();
  298. </script>
  299. @endpush