Google Translate your .desktop files

For efforts in internationalising Puppy and solving problems in this area
Post Reply
Message
Author
User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

Google Translate your .desktop files

#1 Post by sc0ttman »

This script will automatically Translate your .desktop files into the given language, using Google.

NOTE, translations will not be perfect, sometimes really bad, but it is a start.
Existing translations for the chosen language will not be replaced.

Save the code below into a script called 'dotdesktop_translate' and make it executable.
Move it to /usr/local/bin, or similar, then run the script through the terminal, like so:

Code: Select all

dotdesktoptranslate LANG
LANG could be any Google supported language code: de, es, fr, ru, nl, jp, and so on.

Code: Select all

#!/bin/sh
[ "$1" = "" ] && echo "Usage: $(basename $0) LANG
LANG can be any language supported by Google translate:
es, de, fr, ru, nl, jp, etc" && exit
LOC=$1
DIR="/tmp/${LOC}"
[ -d ${DIR} ] || mkdir ${DIR}
for file in /usr/share/applications/*; do
	name=""
	name_loc=""
	# get the english name
	[ -f $file ] && name=$(cat $file | grep '^Name=')
	# cut out anything google translate does not like
	name=${name#*[}
	name=${name%]*}
	name=${name#*=}
	# do not translate the word Puppy 
	name=${name/Puppy /xpupx }
	name=${name/cli /console } # fix for other langs
	name=${name/CLI /console } # fix for other langs
	desc=`echo ${name#* }`
	desc_lower=`echo $desc | tr A-Z a-z` # make lower case
	[ "$desc" != "$name" ] && name=${name/$desc/$desc_lower} # make description lower case in name
	# now check $file for translation we created
	checkname=$(cat "$file" | grep "^Name\[$LOC\]")
	if [ "$checkname" = "" ];then
		echo "Please wait, translating '$(basename $file)' to $LOC..."
		# translation not found, so get translation from Google, sleep a bit, or Google reports 'abuse of service' as a translation :(
		sleep 4.${RANDOM}
		name_loc=`wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=${name}&langpair=en|${LOC}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'`
		# put 'Puppy' back in
		name_loc=${name_loc/xpupx /Puppy }
		name_loc=${name_loc/\u0026\#39\;/\`} # correction for french
		# create proper menu entry
		name_loc=Name[${LOC}]=${name_loc}
		# create file containing the translation, for backup purposes
		#echo $name_loc > $DIR/$(basename $file)
		# if all is well, add the translation to $file
		[ "$(echo $name_loc | grep responseData)" = "" ] && [ "$name_loc" != "" ] && echo "$name_loc" >> "$file"
		echo "Added $LOC translation to $(basename $file)...
		"
	else
		echo "Translation for $LOC already exists in $(basename $file)...
		"
	fi
done 

#remove backup files created
#rm $DIR/*
#rmdir $DIR
Last edited by sc0ttman on Sun 21 Aug 2011, 14:13, edited 3 times in total.
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: Google Translate your .desktop files

#2 Post by L18L »

sc0ttman wrote: LANG could be any Google supported language code: de, es, fr, ru, nl, jp, and so on.
and so on is:

af:Afrikaans
ar:ية
be:Белару

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#3 Post by sc0ttman »

Thanks L18L, yep that's the list..
Also I added a few fixes, including one for French.. Updated code in 1st post.
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#4 Post by sc0ttman »

Unfortunately, I think this script does not work anymore, as Google changed/removed their API :(
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

gojko
Posts: 13
Joined: Thu 25 Nov 2010, 08:48
Location: Hungary

#5 Post by gojko »

Can you modify this script, so that translate in text file?
Google to replace a language text file.

Post Reply