0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ArduBlock のソースを日本語デコード済みにする(UTF-8 エスケープシーケンスのデコード)

Last updated at Posted at 2023-03-31

Arduino のブロックプログラム環境である Ardublock。

image.png

ArduBlock は各国語に対応しているが、それの記述は
src/main/resources/com/ardublock/block
にある。

$ ls
LCD16by2.png             ardublock_de.properties     ardublock_pl.properties     arduino                   linksprite
LCD20by4.png             ardublock_el.properties     ardublock_pt_BR.properties  block-mapping.properties  littlebits
SG90.png                 ardublock_es_ES.properties  ardublock_pt_PT.properties  bulk                      makeblock
Skins                    ardublock_fi.properties     ardublock_ro.properties     dfrobot                   motor.jpg
adafruit                 ardublock_fr.properties     ardublock_ru.properties     esplora                   network
ardublock.properties     ardublock_he.properties     ardublock_sr.properties     i18n.rb                   save_format.dtd
ardublock.xml            ardublock_hu.properties     ardublock_sv_SE.properties  i18n.sh                   seeedstudio
ardublock_af.properties  ardublock_it.properties     ardublock_tr.properties     jerusalab                 trash.png
ardublock_ar.properties  ardublock_ja.properties     ardublock_uk.properties     keenlon                   trash_open.png
ardublock_ca.properties  ardublock_ko.properties     ardublock_vi.properties     keyboard.png              ultrasonic.jpg
ardublock_cs.properties  ardublock_nl.properties     ardublock_zh_CN.properties  keypad_12_button.png      ultrasonic.png
ardublock_da.properties  ardublock_no.properties     ardublock_zh_TW.properties  lang_def.dtd              workshop

ardublock_ja.properties が日本語用のファイルなのだが

$ head ardublock_ja.properties 
#X-Generator: crowdin.com
bc.start=\u30b9\u30bf\u30fc\u30c8
bc.end=\u30b9\u30c8\u30c3\u30d7
bg.constrain=\u5236\u9650
bc.low=\u304b\u3089
bc.high=\u307e\u3067
bg.sd_write2=SD\u30ab\u30fc\u30c9\u3078\u306e\u66f8\u304d\u8fbc\u3080
bg.sd_write=SD \u30d5\u30e9\u30c3\u30b7\u30e5\u66f8\u304d\u8fbc\u307f
bg.sd_return=\u623b\u308b
bd.storage=\u30b9\u30c8\u30ec\u30fc\u30b8

このようにエスケープシーケンスになっているのでたいへん編集しづらい。
以前は UTF-8 で日本語を記述するとエラーになったようだが、今だと問題ないようなのでファイルをデコードして扱うことにした。

環境

  • Ubuntu 22.04
  • openjdk 11.0.17 2022-10-18

「Ardublock を Docker でビルドする」
https://qiita.com/nanbuwks/items/1a576859987e463264c3
で構築した環境上で行った。

準備

$ sudo apt install nkf

作業

「コマンドライン上でのunicode escape sequenceのデコード | IR.0-4の日記 | スラド」
https://srad.jp/~IR.0-4/journal/575464/

を参考にして、

$ FILE=ardublock_ja.properties ; cp $FILE $FILE.back ; cat $FILE.back  | sed -e 's/\\u\(....\)/\&#x\1;/g' | nkf --numchar-input | head

とすると

#X-Generator: crowdin.com
bc.start=スタート
bc.end=ストップ
bg.constrain=制限
bc.low=から
bc.high=まで
bg.sd_write2=SDカードへの書き込む
bg.sd_write=SD フラッシュ書き込み
bg.sd_return=戻る
bd.storage=ストレージ

となって良さそうだったので、

$ FILE=ardublock_ja.properties ; cp $FILE $FILE.back ; cat $FILE.back  | sed -e 's/\\u\(....\)/\&#x\1;/g' | nkf --numchar-input > $FILE

とします。動かしてみて問題なければardublock_ja.properties.back は削除します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?