Shell file on google translate

Discuss, plan, and make Translations for FreeOrion
Post Reply
Message
Author
nanimosinaihito
Space Krill
Posts: 2
Joined: Mon Oct 07, 2019 12:20 pm

Shell file on google translate

#1 Post by nanimosinaihito » Tue Oct 08, 2019 11:01 am

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.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12486
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shell file on google translate

#2 Post by Geoff the Medio » Tue Oct 08, 2019 12:05 pm

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?

nanimosinaihito
Space Krill
Posts: 2
Joined: Mon Oct 07, 2019 12:20 pm

Re: Shell file on google translate

#3 Post by nanimosinaihito » 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.

Ophiuchus
Programmer
Posts: 1045
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Shell file on google translate

#4 Post by Ophiuchus » Wed Oct 09, 2019 9:07 am

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)
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Furthermore, I propse... we should default to four combat rounds instead of three ...for the good of playerkind.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12486
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shell file on google translate

#5 Post by Geoff the Medio » Wed Oct 09, 2019 9:18 am

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

Post Reply