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

Re: Shell file on google translate

Posted: Mon Feb 10, 2020 12:26 pm
by nanimosinaihito
I found www.bing.com/translator.
I think it dont have a quota per time.
So,script finished its job.
but, it has some problems.
I couldn't solve this problems.
Before translating, I tried to replace [something] with another one and then revert to it, but I didn't know how.
The ability to translate more than two lines is currently being created.

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
		transted=`trans en:ja -b -e bing "$twice" -no-auto`
#		if [ -n $transted  ]; then
#			sleep 30m
#			transted=`trans en:ja -b -e bing "$twice" -no-auto`
#			transted=`echo $transted | tr -d " "`
#		fi
		read transted < <(echo $transted | tr '\n' ' ')
		result=`echo $string | cut -c 4-6`
		echo $transted
		sleep 5
	else 
		echo $twice
	fi
else
	echo $line
fi	
	#trans :ja -b $line -no-auto
done < ./en.txt

Re: Shell file on google translate

Posted: Mon Feb 10, 2020 12:36 pm
by adrian_broher
Why don't you do proper translations and contribute them to the project?

Re: Shell file on google translate

Posted: Mon Feb 10, 2020 2:32 pm
by nanimosinaihito
Does that mean using this script?

Re: Shell file on google translate

Posted: Mon Feb 10, 2020 2:36 pm
by Oberlus
Manual translation (if you understand English and you are a native speaker of the target language).

Re: Shell file on google translate

Posted: Mon Feb 10, 2020 2:47 pm
by nanimosinaihito
After I have completed this script, I will run it, but I will make some modifications afterwards.
This work will not be completed by me alone because there are few Japanese people.
But I am also working on manual translation.

Re: Shell file on google translate

Posted: Wed Feb 12, 2020 8:41 am
by nanimosinaihito
Where should I upload the completed ja.txt

Re: Shell file on google translate

Posted: Wed Feb 12, 2020 9:17 am
by Geoff the Medio
nanimosinaihito wrote: Wed Feb 12, 2020 8:41 am Where should I upload the completed ja.txt
Ideally you would make a github account and create a pull request.

Alternatively, you can zip it and include an attachment on a forum post.

Re: Shell file on google translate

Posted: Wed Feb 12, 2020 10:02 am
by nanimosinaihito
My script did its job.

Re: Shell file on google translate

Posted: Wed Feb 12, 2020 11:36 am
by Geoff the Medio
So did you just use google translate to process the english file, or did you do any substantial editing and correction of the result? If you didn't do any substantial translation then w probably don't need a statement that you release any vöchanges under the CC BY SA 3.0 license, but it would be good if you wrote a post stating that anything you submit is under that license anyway...

https://github.com/freeorion/freeorion/ ... lt/COPYING