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 22 Dec 2014, 04:44
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 Posts_count  
Author Message
sc0ttman


Joined: 16 Sep 2009
Posts: 2387
Location: UK

PostPosted: Sun 21 Aug 2011, 09:14    Post_subject:  Google Translate your .desktop files
Sub_title: 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

Edited_times_total
Back to top
View user's profile Send_private_message 
L18L

Joined: 19 Jun 2010
Posts: 2620
Location: www.eussenheim.de/

PostPosted: Sun 21 Aug 2011, 09:30    Post_subject: Re: Google Translate your .desktop files
Sub_title: 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: 2387
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: 2387
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Puppy Projects » Localization Project
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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