Discuss Scratch

Scratchnosekai
Scratcher
100+ posts

Conversion to numbers

Japanese and English (Kanji, Hiragana, Katakana, symbols, etc…) in Python to numbers, and want to convert them back to the original Japanese and English in Scratch.
8to16
Scratcher
1000+ posts

Conversion to numbers

This is a technique used to store data in cloud variables, just map each character to the numbers you used in the python script
Maximouse
Scratcher
1000+ posts

Conversion to numbers

8to16 wrote:

This is a technique used to store data in cloud variables, just map each character to the numbers you used in the python script
Japanese has a lot of characters, so doing this by hand probably wouldn't be practical. On the Python side, the ord() function will be helpful. For the Scratch side, a list of characters could be generated with Python and then imported to Scratch.
ninjaMAR
Scratcher
1000+ posts

Conversion to numbers

Maximouse wrote:

(#3)
Japanese has a lot of characters, so doing this by hand probably wouldn't be practical. On the Python side, the ord() function will be helpful. For the Scratch side, a list of characters could be generated with Python and then imported to Scratch.
# This is a list of ranges of the codepoints for Japanese characters in unicode
# https://www.localizingjapan.com/blog/2012/01/20/regular-expressions-for-japanese-text/
# This list is stored in the format [lowest, highest]
codepoint_ranges = [
    [0x3041, 0x3096], # Hirangana
    [0x30A0, 0x30FF], # Katakana
    [0x3400, 0x4DB5], # Kanji (+Chinese)
    [0x4E00, 0x9FCB], # Kanji (+Chinese)
    [0xF900, 0xFA6A], # Kanji (+Chinese)
    [0x2E80, 0x2FD5], # Kanji Radicals
    [0xFF5F, 0xFF9F], # Katakana and Punctuation 
    [0x3000, 0x303F], # Japanese Symbols and Punctuation
    [0x31F0, 0x31FF], # Miscellaneous Japanese Symbols and Characters
    [0x3220, 0x3243], # Miscellaneous Japanese Symbols and Characters
    [0x3280, 0x337F], # Miscellaneous Japanese Symbols and Characters
    [0xFF01, 0xFF5E] # Alphanumeric and Punctuation (Full Width) 
]
# Turn the codepoint ranges into one list of codepoints
codepoints = []
for range_ in codepoint_ranges:
    for point in range(range_[0] + 1, range_[1] + 1):
        codepoints.append(point)
# Turn the codepoints into a symbol using chr(codepoint)
symbols = [chr(i) for i in codepoints]
# If you want to get a codepoint from a symbol, use ord(symbol)

This code generates all of the codepoints (numbers) and stores it in the codepoints list. It shows the symbols that correspond to the codepoint in the symbols list.

Powered by DjangoBB