Hiragana Translater Module

This is a hiragana translater, you can translate text and into hiragana!

Here is an example

local hirigana = require(workspace.Hirigana)
print(hirigana.translationTable) -- prints the translation table
print(hirigana.translate("kawaii neko to inu desu.")) -- a cute cat and dog, should translate into かわいい ねこ と いぬ です。
9 Likes

would you add support for other languages like Greek?

1 Like

i might in the future, but i cant rn heres how you can do it your self if you want to.
what you have to do is replace the keys in the translationTable with the english version, then replace the values with the greek version
example:
make a key called “d” and then set the value to Δ

4 Likes

Ok, but I recommend changing the while - <= #text do to for i = 1, #text do

this is the code snippet

function module.translate(text)
	local hiraganaText = ""

	local i = 1
	while i <= #text do
		local char = text:sub(i, i)

		
		local twoCharSequence = text:sub(i, i + 1)
		if module.translationTable[twoCharSequence] then
			hiraganaText = hiraganaText .. module.translationTable[twoCharSequence]
			i = i + 2  
		else
			-- If not a valid sequence, check for a single character match
			local singleCharSequence = text:sub(i, i)
			if module.translationTable[singleCharSequence] then
				hiraganaText = hiraganaText .. module.translationTable[singleCharSequence]
			else
				
				hiraganaText = hiraganaText .. char
			end
			i = i + 1 
		end
	end

	return hiraganaText
end

and this is my version

function module.translate(text)
	local hiraganaText = ""
	
	for i = 1, #text do
		local char = text:sub(i, i)


		local twoCharSequence = text:sub(i, i + 1)
		if module.translationTable[twoCharSequence] then
			hiraganaText ..= module.translationTable[twoCharSequence]
			i += 2  
		else
			-- If not a valid sequence, check for a single character match
			local singleCharSequence = text:sub(i, i)
			if module.translationTable[singleCharSequence] then
				hiraganaText ..= module.translationTable[singleCharSequence]
			else

				hiraganaText ..= char
			end
			i += 1 
		end
	end

	return hiraganaText
end
2 Likes

bro, it’s for one language

did you not see the title?

4 Likes

ik, but I want it to work for uppercase letters, not lowercase

1 Like

that doesn’t have anything to do with other langauges

1 Like

did you know other languages have uppercase letters? especially if they don’t use the latin alphabet?

Uppercase LAMP transliteration

ΛΑΜΠ
ЛАМП
ԼԱՄՊ

lowercase lamp transliteration

λαμπ
ламп
լամպ

this is proof

1 Like