Page 1 of 1

Shell file on google translate

Posted: Tue Oct 08, 2019 11:01 am
by nanimosinaihito
Hello
I wanted to play freeorion in Japanese
I wrote this code to translate freeorion into Japanese.
I moved freeorion/default/stringtables/en.txt in the same folder.

Code: Select all

#!/bin/bash
while IFS= read line
do
if [[ $line =~ ^#.*	]] ; then
	echo $line
elif [[ $line =~ ^[A-z].* ]] ; then
	echo $line
	read twice
	if [[	$twice =~ .*%.* ]] ; then
		echo $twice	
	elif [[	$twice =~ .*\(.* ]] ; then
		echo $twice
	elif [[	$twice =~ .*\[.* ]] ; then
		echo $twice
	elif [[	$twice =~ .*\{.* ]] ; then
	 	echo $twice
	elif [[	$twice =~ .*\<.* ]] ; then
		echo $twice
	elif [[ $twice =~ ^[A-z].* ]] ; then
		trans :ja -b $twice -no-auto
		sleep 10
		
	else 
		echo $twice
	fi
else
	echo $line
fi	
	#trans :ja -b $line -no-auto
done < ./en.txt

I made it and new.txt.and,I moved it in the terminal.

Code: Select all

translate.sh >new.txt
This code doesn't work correctly.
But it moved halfway.
I am a shell beginner.
If you ask some advice, I think it will work.
translate.sh
I am Japanese.,I may made a mistake in grammar.

Re: Shell file on google translate

Posted: Tue Oct 08, 2019 12:05 pm
by Geoff the Medio
What do you want tge script to do that you can't or don't want to do by opening the stringtable in a text editor and editing it line by line?

Re: Shell file on google translate

Posted: Wed Oct 09, 2019 7:07 am
by nanimosinaihito
If there is a two-line string
If the first character on the second line is alphabetic, the second line is translated.
However, if I use the translation command several times, it will stop working.

Re: Shell file on google translate

Posted: Wed Oct 09, 2019 9:07 am
by Ophiuchus
nanimosinaihito wrote:
Wed Oct 09, 2019 7:07 am
If there is a two-line string
If the first character on the second line is alphabetic, the second line is translated.
However, if I use the translation command several times, it will stop working.
Probably google translate has a quota per time. You could send the process to sleep for lets say half a minute after each translate.
Or you could create single output file which you send completely to translate. Instead of the comments and keys use empty lines. Just leave the stuff for translation in.
Then send it to translate and then you need to merge the translation back into the original file.

But batch translate will be very bad for the many snippets we have as you need to know where that snippets are used and in which context.
So I guess - if your english and japanese are good and you know the game - doing it manually line by line will probably be the best approach. (For longer texts you could have google translate open anyways)

Re: Shell file on google translate

Posted: Wed Oct 09, 2019 9:18 am
by Geoff the Medio
Perhaps it would be helpful to look at the regex code FreeOrion uses to parse the stringtables?

https://github.com/freeorion/freeorion/ ... le.cpp#L81