-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎉🎉🎉 create translator web site
- Loading branch information
1 parent
ea18d2d
commit 1c288dd
Showing
13 changed files
with
415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
*.annot | ||
*.cmo | ||
*.cma | ||
*.cmi | ||
*.a | ||
*.o | ||
*.cmx | ||
*.cmxs | ||
*.cmxa | ||
|
||
# ocamlbuild working directory | ||
_build/ | ||
|
||
# ocamlbuild targets | ||
*.byte | ||
*.native | ||
|
||
# oasis generated files | ||
setup.data | ||
setup.log | ||
|
||
# Merlin configuring file for Vim and Emacs | ||
.merlin | ||
|
||
# Dune generated files | ||
*.install | ||
|
||
# Local OPAM switch | ||
_opam/ | ||
|
||
# node_modules | ||
node_modules/ | ||
|
||
# dotenv files | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# アルベド語自動翻訳サイト | ||
|
||
https://proof-ninja.github.io/albhed/ | ||
|
||
## アルベド語とはなんですか | ||
|
||
* see: https://www.jp.square-enix.com/column/detail/3/ | ||
|
||
## Requirement | ||
|
||
```console | ||
opam install js_of_ocaml-ppx | ||
``` | ||
|
||
## How to try this | ||
|
||
```console | ||
./compile.sh | ||
open index.html | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(executable | ||
(name main) | ||
(modes js) | ||
(libraries uutf) | ||
(preprocess (pps js_of_ocaml-ppx))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
open Js_of_ocaml | ||
open Translate | ||
|
||
let get_params () : (string * string) list = Url.Current.arguments | ||
let query key params = List.assoc_opt key params | ||
|
||
type operator = | ||
Init | Translate of lang * string | ||
|
||
let operator_of_params params = | ||
match (query "lang" params , query "ja" params, query "al" params) with | ||
| (Some "al2ja", _, al) -> | ||
let text = Option.value al ~default:"" in | ||
Translate (Albhed_to_Ja, text) | ||
| (Some "ja2al", ja, _) -> | ||
let text = Option.value ja ~default:"" in | ||
Translate (Ja_to_Albhed, text) | ||
| _ -> Init | ||
|
||
let init () = | ||
print_endline "init"; | ||
(Dom_html.getElementById_exn "tweet")##.innerHTML := Js.string (Tweet_button.show Albhed_to_Ja "マギレヤキセ"); | ||
() | ||
let translate lang src = | ||
print_endline "translate"; | ||
let dst = Translate.f lang src in | ||
(Dom_html.getElementById_exn "tweet")##.innerHTML := Js.string (Tweet_button.show lang src); | ||
match lang with | ||
| Albhed_to_Ja -> | ||
(Dom_html.getElementById_exn "japanese")##.innerText := Js.string dst; | ||
(Dom_html.getElementById_exn "albhed")##.innerText := Js.string src | ||
| Ja_to_Albhed -> | ||
(Dom_html.getElementById_exn "japanese")##.innerText := Js.string src; | ||
(Dom_html.getElementById_exn "albhed")##.innerText := Js.string dst | ||
|
||
let onload _ = | ||
let params = get_params () in | ||
begin match operator_of_params params with | ||
| Init -> init () | ||
| Translate (lang, text) -> translate lang text | ||
end; | ||
Js._false | ||
|
||
|
||
let () = | ||
Dom_html.window##.onload := Dom_html.handler onload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
type lang = Albhed_to_Ja | Ja_to_Albhed | ||
|
||
let table = [ (*c.f. https://www.jp.square-enix.com/column/detail/3/ *) | ||
("あ", "ワ"); ("い", "ミ"); ("う", "フ"); ("え", "ネ"); ("お", "ト"); | ||
("か", "ア"); ("き", "チ"); ("く", "ル"); ("け", "テ"); ("こ", "ヨ"); | ||
("さ", "ラ"); ("し", "キ"); ("す", "ヌ"); ("せ", "ヘ"); ("そ", "ホ"); | ||
("た", "サ"); ("ち", "ヒ"); ("つ", "ユ"); ("て", "セ"); ("と", "ソ"); | ||
("な", "ハ"); ("に", "シ"); ("ぬ", "ス"); ("ね", "メ"); ("の", "オ"); | ||
("は", "マ"); ("ひ", "リ"); ("ふ", "ク"); ("へ", "ケ"); ("ほ", "ロ"); | ||
("ま", "ヤ"); ("み", "イ"); ("む", "ツ"); ("め", "レ"); ("も", "コ"); | ||
("や", "タ"); ("ゆ", "ヲ"); ("よ", "モ"); | ||
("ら", "ナ"); ("り", "ニ"); ("る", "ウ"); ("れ", "エ"); ("ろ", "ノ"); | ||
("わ", "カ"); ("を", "ム"); | ||
("ん", "ン"); ("っ", "ッ"); | ||
("が", "ダ"); ("ぎ", "ヂ"); ("ぐ", "ヅ"); ("げ", "デ"); ("ご", "ゾ"); | ||
("ざ", "バ"); ("じ", "ギ"); ("ず", "ブ"); ("ぜ", "ゲ"); ("ぞ", "ボ"); | ||
("だ", "ガ"); ("ぢ", "ビ"); ("づ", "グ"); ("で", "ベ"); ("ど", "ゴ"); | ||
("ば", "ザ"); ("び", "ジ"); ("ぶ", "ズ"); ("べ", "ゼ"); ("ぼ", "ド"); | ||
("ぱ", "プ"); ("ぴ", "ポ"); ("ぷ", "ピ"); ("ぺ", "パ"); ("ぽ", "ペ"); | ||
] | ||
|
||
let albhed_to_ja uchar = | ||
match List.find_opt (fun (_ja, al) -> Utf8.uchar_of_string al = uchar) table with | ||
| None -> uchar | ||
| Some (ja, _) -> Utf8.uchar_of_string ja | ||
|
||
let ja_to_albhed uchar = | ||
match List.find_opt (fun (ja, _al) -> Utf8.uchar_of_string ja = uchar) table with | ||
| None -> uchar | ||
| Some (_, al) -> Utf8.uchar_of_string al | ||
|
||
let f lang text = | ||
match lang with | ||
| Albhed_to_Ja -> | ||
Utf8.of_string text | ||
|> Utf8.map albhed_to_ja | ||
|> Utf8.to_string | ||
| Ja_to_Albhed -> | ||
Utf8.of_string text | ||
|> Utf8.map ja_to_albhed | ||
|> Utf8.to_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
open Js_of_ocaml | ||
|
||
let button_text = "アルベド語をツイートする" | ||
|
||
let hashtag = Url.urlencode "アルベド語翻訳" | ||
|
||
let body text = | ||
Printf.sprintf {|%s | ||
|
||
翻訳をみる → |} text | ||
|> Url.urlencode | ||
|
||
let show lang text = | ||
Printf.printf "Tweet_button.show: '%s'" text; | ||
let link = | ||
let query = | ||
match lang with | ||
| Translate.Albhed_to_Ja -> Url.encode_arguments [("lang", "al2ja"); ("al", text)] | ||
| Ja_to_Albhed -> Url.encode_arguments [("lang", "ja2al"); ("ja", text)] | ||
in | ||
let base = "proof-ninja.github.io/albhed" in | ||
"https://" ^ base ^ "?" ^ query | ||
in | ||
Printf.sprintf {|<a href="https://twitter.com/intent/tweet?hashtags=%s&ref_src=&text=%s&url=%s" class="twitter-share-button">%s</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>|} | ||
hashtag | ||
(body text) (Url.urlencode link) button_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
type t = string | ||
|
||
let fold f init ustr = | ||
Uutf.String.fold_utf_8 (fun acc _i -> function | ||
| `Uchar uchar -> f acc uchar | ||
| `Malformed _s -> acc) init ustr | ||
|
||
let map f ustr = | ||
let buf = Buffer.create (String.length ustr) in | ||
fold (fun buf uchar -> Uutf.Buffer.add_utf_8 buf (f uchar); buf) buf ustr | ||
|> Buffer.contents | ||
|
||
let uchar_of_string s = | ||
let decoder = Uutf.decoder ~encoding:`UTF_8 (`String s) in | ||
match Uutf.decode decoder with | ||
| `Uchar u -> u | ||
| _ -> failwith "Invalid UTF-8 character" | ||
|
||
let string_of_uchar uchar = | ||
let buf = Buffer.create 4 in | ||
Uutf.Buffer.add_utf_8 buf uchar; | ||
Buffer.contents buf | ||
|
||
let of_string s = s | ||
let to_string s = s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type t | ||
|
||
val fold : ('a -> Uchar.t -> 'a) -> 'a -> t -> 'a | ||
val map : (Uchar.t -> Uchar.t) -> t -> t | ||
|
||
val uchar_of_string : string -> Uchar.t | ||
val string_of_uchar : Uchar.t -> string | ||
|
||
val of_string : string -> t | ||
val to_string : t -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set -eux | ||
dune build bin/main.bc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(alias | ||
(name default) | ||
(deps | ||
bin/main.bc.js | ||
index.html | ||
(glob_files statics/*)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(lang dune 3.0) | ||
|
||
(name jsoo-alhbed) | ||
|
||
(generate_opam_files true) | ||
|
||
(source | ||
(github username/reponame)) | ||
|
||
(authors "Yoshihiro Imai") | ||
|
||
(maintainers "Yoshihiro Imai") | ||
|
||
(license LICENSE) | ||
|
||
(documentation https://url/to/documentation) | ||
|
||
(package | ||
(name jsoo-alhbed) | ||
(synopsis "A short synopsis") | ||
(description "A longer description") | ||
(depends ocaml dune js_of_ocaml-ppx uutf) | ||
(tags | ||
(topics "to describe" your project))) | ||
|
||
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<html> | ||
<head> | ||
<script type="text/javascript" src="bin/main.bc.js"></script> | ||
<link href="statics/style.css" rel="stylesheet" type="text/css" /> | ||
</head> | ||
<body> | ||
<form id="translator"> | ||
<div class="container"> | ||
<div class="head"> | ||
<h2>アルベド語 翻訳</h2> | ||
</div> | ||
<label for="albhed">アルベド語</label><br /> | ||
<textarea id="albhed" name="al" placeholder="マギレヤキセ"></textarea><br /> | ||
|
||
<input type="radio" id="al2ja" name="lang" value="al2ja" checked /> | ||
<label for="al2ja">↓アル日翻訳</label> | ||
<input type="radio" id="ja2al" name="lang" value="ja2al" /> | ||
<label for="ja2al">↑日アル翻訳</label><br /> | ||
|
||
<textarea id="japanese" name="ja"></textarea><br /> | ||
|
||
<div class="message">Message Sent</div> | ||
<button id="submit" type="submit">翻訳!</button> | ||
|
||
<div id="tweet"></div> | ||
</div> | ||
</form> | ||
</body> | ||
</html> |
Oops, something went wrong.