Function using GOOGLE translate to translate HELP's of commands

by

 

%The purpose of this code is to use GOOGLE translate to %translate help of a command in MATLAB

helptr.m
function helptr(command_string)

%This code is written by M.A. (aka lftx). 
%The purpose of this code is to use GOOGLE translate to
%translate help of a command in MATLAB to Turkish (you can modify it).
%So do not expect much.
%
%You need an active internet connection for this function to work
%
%The function uses a java package to use GOOGLE translate's API
%which is not developed by me, for detailed description of the java
%files you can check 
%http://code.google.com/p/google-api-translate-java/
%
%the usage of the file is very similar to the original "help" function
%and if you add the files to your matlab's path you can use it as you use
%MATLAB "help" function 
%
%EXAMPLES: helptr eye
%EXAMPLES: helptr('why') or helptr why
%
%The function has been working as of DEC 2010
%I cannot guarantee that it would be working in the future, as google might
%change its API, or might not like your referring webpage or maybe your IP.


%Bu kod M.A.(lftx) tarafindan yazilmistir.
%Kodun amaci GOOGLE translate kullanarak bir MATLAB komutunun yardim 
%dokumanini Turkceye(bu degistirilebilir) cevirmektir.
%Yani cevirinin cok guzel olmasini beklemeyin.
%
%Bu fonksiyonun calismasi icin internete bagli olmaniz gerekmektedir.
%
%Bu fonksiyon GOOGLE translate kullanabilmek icin, benim tarafimdan 
%gelistirilmemis olan bir java paketi kullanmaktadir, bu java paketinin 
%detaylari icin asagidaki adresi ziyaret edebilirsiniz.
%
%http://code.google.com/p/google-api-translate-java/
%
%Bu fonksiyonun kullanimi, orjinal "help" komutuyla cok benzerdir, bu fonksiyon klasorunu
%MATLAB in path'ine koyarsaniz "help" fonksiyonunu kullandiginiz gibi kullanabilirsiniz.
%
%
%ORNEKLER: helptr eye
%ORNEKLER: helptr('why') or helptr why
%
%Bu fonksiyon ARALIK 2010 tarihi itibariyle calismaktadir,
%Ancak malesef gelcekte calisacagini garanti edemem cunku 
%GOOGLE kullandigi alt yapiyi degistirebilir,
%veya sistemi kullanmak icin kullandiginiz yonlendirici sayfayi
%sevmeyebilir veya sizin IP'nizden hoslanmayabilir.


p=mfilename('fullpath');
n=mfilename;
curr_directory=p(1:strfind(p,n)-2);
java_folder='\google_translate_api\com.jar';
google_translate_path=[curr_directory java_folder];
javaaddpath(google_translate_path);

languageFrom = com.google.api.translate.Language.ENGLISH;
languageTo = com.google.api.translate.Language.TURKISH;

referrer=java.lang.String('www.your_home_page.com');  
%%%if the function is not working you might need to change this webpage name to another name

%%%Fonksiyon calismiyorsa burdaki web adresini baska bir web adresine
%%%degistirmeniz gerekebilir, ama yinede calisacagini garanti etmez.

com.google.api.translate.Translate.setHttpReferrer(referrer);

help_in_english=help(command_string);
help_in_another=[];
nl=char(13);
dot=int8('.');
space=int8(' ');

dots=find((int8(help_in_english)==dot));
sentences=[];
for(dt=1:length(dots))
    if(int8(help_in_english(dots(dt)+1))==space | int8(help_in_english(dots(dt)+1))==13 | int8(help_in_english(dots(dt)+1))==10 )
        sentences=[sentences dots(dt)];
    end
end
    
st=1;

for(sentence=1:length(sentences))
    
    help_in_english_sentence_java=java.lang.String(help_in_english(st:sentences(sentence)));
    help_in_another_sentence_java=com.google.api.translate.Translate.translate(help_in_english_sentence_java, languageFrom, languageTo);
    help_in_another=[help_in_another,char(help_in_another_sentence_java),help_in_english(sentences(sentence)+1)];
    st=sentences(sentence)+2;
end

modified_help=[nl,'Orjinal yardm dosyasi--------------',nl,nl,help_in_english,nl,nl,'Ceviri yardm dosyasi---------------',nl,nl,help_in_another];
disp(modified_help)

Contact us