Shell file on google translate

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

Shell file on google translate

#1 Post 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.

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

Re: Shell file on google translate

#2 Post 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?

nanimosinaihito
Space Floater
Posts: 29
Joined: Mon Oct 07, 2019 12:20 pm
Location: japan

Re: Shell file on google translate

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

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

Re: Shell file on google translate

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

Look, ma... four combat bouts!

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

Re: Shell file on google translate

#5 Post 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

nanimosinaihito
Space Floater
Posts: 29
Joined: Mon Oct 07, 2019 12:20 pm
Location: japan

Re: Shell file on google translate

#6 Post 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

User avatar
adrian_broher
Programmer
Posts: 1156
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: Shell file on google translate

#7 Post by adrian_broher »

Why don't you do proper translations and contribute them to the project?
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

nanimosinaihito
Space Floater
Posts: 29
Joined: Mon Oct 07, 2019 12:20 pm
Location: japan

Re: Shell file on google translate

#8 Post by nanimosinaihito »

Does that mean using this script?

User avatar
Oberlus
Cosmic Dragon
Posts: 5704
Joined: Mon Apr 10, 2017 4:25 pm

Re: Shell file on google translate

#9 Post by Oberlus »

Manual translation (if you understand English and you are a native speaker of the target language).

nanimosinaihito
Space Floater
Posts: 29
Joined: Mon Oct 07, 2019 12:20 pm
Location: japan

Re: Shell file on google translate

#10 Post 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.

nanimosinaihito
Space Floater
Posts: 29
Joined: Mon Oct 07, 2019 12:20 pm
Location: japan

Re: Shell file on google translate

#11 Post by nanimosinaihito »

Where should I upload the completed ja.txt

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

Re: Shell file on google translate

#12 Post 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.

nanimosinaihito
Space Floater
Posts: 29
Joined: Mon Oct 07, 2019 12:20 pm
Location: japan

Re: Shell file on google translate

#13 Post by nanimosinaihito »

My script did its job.
Attachments
ja.tar.gz
(153.05 KiB) Downloaded 190 times

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

Re: Shell file on google translate

#14 Post 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

Post Reply