Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 28 Jul 2014, 04:32
All times are UTC - 4
 Forum index » Advanced Topics » Puppy Projects » Localization Project
Google Translate your .desktop files
Moderators: Lobster, MU, raffy
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
sc0ttman


Joined: 16 Sep 2009
Posts: 2373
Location: UK

PostPosted: Sun 21 Aug 2011, 09:14    Post subject:  Google Translate your .desktop files
Subject description: does what it says above
 

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:
dotdesktoptranslate LANG

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

Code:
#!/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

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search

Last edited by sc0ttman on Sun 21 Aug 2011, 10:13; edited 3 times in total
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Sun 21 Aug 2011, 09:30    Post subject: Re: Google Translate your .desktop files
Subject description: does what it says above
 

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:Беларуская
bg:Български
ca:Català
cy:Cymraeg
cs:České
da:Danske
el:Ελληνικά
et:Eesti
fa:فارسی
fi:Suomi
ga:Na hÉireann
gl:Galego
hi:Hindī
hr:Hrvatski
hu:Magyar
id:Bahasa Indonesia
is:Íslenska
it:Italiano
iw:עברית
ko:hangug-eo
lv:Latvijā
lt:Lietuvos
mk:Македонски
ms:Melayu
mt:Malti
no:Norske
pl:Polska
pt:Português
ro:Română
sk:Slovenskému
sl:Slovenščina
sq:Shqiptar
sr:Српска
sv:Svenska
th:ไทย
tr:Türk
uk:Українське
vi:Việt
yi:ייִדיש
zh-CN:Jiǎntǐ zhōngwén
zh-TW:Zhōngguó chuántǒng

Hope that helps Smile
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2373
Location: UK

PostPosted: Sun 21 Aug 2011, 10:14    Post subject:  

Thanks L18L, yep that's the list..
Also I added a few fixes, including one for French.. Updated code in 1st post.

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2373
Location: UK

PostPosted: Tue 24 Jan 2012, 14:25    Post subject:  

Unfortunately, I think this script does not work anymore, as Google changed/removed their API Sad
_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send private message 
gojko

Joined: 25 Nov 2010
Posts: 13
Location: Hungary

PostPosted: Thu 29 Mar 2012, 14:40    Post subject:  

Can you modify this script, so that translate in text file?
Google to replace a language text file.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Puppy Projects » Localization Project
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0561s ][ Queries: 12 (0.0033s) ][ GZIP on ]