Home » SQL & PL/SQL » SQL & PL/SQL » Code to Convert English Names to Arabic (oracle 10g)
Code to Convert English Names to Arabic [message #503515] Sun, 17 April 2011 02:04 Go to next message
shanie
Messages: 118
Registered: January 2011
Senior Member
Hi,

I need Code or Procedure which can convert
English Names to Arabic Names in Oracle.

Like Given Student ID it fetch Student Name
But I need to Convert this name to Arabic.

Please share if you have any solution.

Regards,
Shanie
Re: Code to Convert English Names to Arabic [message #503520 is a reply to message #503515] Sun, 17 April 2011 05:18 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
So what would be the "Arabic" name for "Martin Scorsese" for examle?
Re: Code to Convert English Names to Arabic [message #503522 is a reply to message #503520] Sun, 17 April 2011 07:22 Go to previous messageGo to next message
shanie
Messages: 118
Registered: January 2011
Senior Member
Hi,

There is no change in pronounciation.
I do not want any meaning of any word in Arabic.

what 'Martin' is pronounced and written in English,
the same should be pronounced and written in Arabic.

I hope you understand.

Regards,
Shanie
Re: Code to Convert English Names to Arabic [message #503533 is a reply to message #503522] Sun, 17 April 2011 11:17 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
I can't say I do understand. As far as we're aware names don't translate. So unless you explain the rules of this translation no-one is going to be able to help you.
Re: Code to Convert English Names to Arabic [message #503536 is a reply to message #503533] Sun, 17 April 2011 12:25 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
I don't know the Arabic alphabet or have your character set. What you can do is create a table with the letters of the English alphabet in one column and the corresponding letters of the Arabic alphabet in the other column, then create a function that will replace the letters one at a time. I have demonstrated below, using lower case letters instead of Arabic letters.

SCOTT@orcl_11gR2> create table english_arabic
  2    (english  varchar2 (1),
  3  	arabic	 nvarchar2 (4))
  4  /

Table created.

SCOTT@orcl_11gR2> insert into english_arabic values
  2    ('M', 'm')
  3  /

1 row created.

SCOTT@orcl_11gR2> insert into english_arabic values
  2    ('A', 'a')
  3  /

1 row created.

SCOTT@orcl_11gR2> insert into english_arabic values
  2    ('R', 'r')
  3  /

1 row created.

SCOTT@orcl_11gR2> insert into english_arabic values
  2    ('T', 't')
  3  /

1 row created.

SCOTT@orcl_11gR2> insert into english_arabic values
  2    ('I', 'i')
  3  /

1 row created.

SCOTT@orcl_11gR2> insert into english_arabic values
  2    ('N', 'n')
  3  /

1 row created.

SCOTT@orcl_11gR2> create or replace function english_to_arabic
  2    (p_english in varchar2)
  3    return nvarchar2
  4  as
  5    v_arabic      nvarchar2 (4);
  6    v_result      nvarchar2 (4000);
  7  begin
  8    for i in 1 .. length (p_english) loop
  9  	 select arabic
 10  	 into	v_arabic
 11  	 from	english_arabic
 12  	 where	english = substr (p_english, i, 1);
 13  	 v_result := v_result || v_arabic;
 14    end loop;
 15    return v_result;
 16  end english_to_arabic;
 17  /

Function created.

SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select english_to_arabic ('MARTIN') from dual
  2  /

ENGLISH_TO_ARABIC('MARTIN')
--------------------------------------------------------------------------------
martin

1 row selected.

SCOTT@orcl_11gR2>

Re: Code to Convert English Names to Arabic [message #503642 is a reply to message #503536] Mon, 18 April 2011 10:00 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
Please see the following thread for additional solutions.

http://www.orafaq.com/forum/t/170320/43710/
Re: Code to Convert English Names to Arabic [message #503643 is a reply to message #503642] Mon, 18 April 2011 10:14 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
Hi Barbara,

I doubted http://www.orafaq.com/forum/t/170320/43710/ will help here (and I noted it in the post you are referring to). AFAIU, Shanie needs to translate proper names and Google translator does not do it. Altough, Shanie could look for other on-line translators that deal with proper names (obviously he/she will have to figure out the interface).

SY.
Re: Code to Convert English Names to Arabic [message #503645 is a reply to message #503643] Mon, 18 April 2011 11:04 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
Solomon,

I believe it does work. I tried entering "Martin Scorsese" and translating English to Arabic and got a result in Arabic characters reading right to left. I copied and pasted that result and used it to convert Arabic to English and got "Martin Scorsese". I had already tested that before I gave up trying to create the function in the other thread and resorted to the one in this thread. Please see the links below for the name conversion example. Note that Arabic is right to left, so look for the translated name in the rightmost portion of the translation box.

http://translate.google.com/#en|ar|Martin%20Scorsese

http://translate.google.com/#ar|en|%D9%85%D8%A7%D8%B1%D8%AA%D9%86%20%D8%B3%D9%83%D9%88%D8%B1%D8%B3%D9%8A%D8%B2%D9%8A

Also note the conversion of the English "John Paul" to the French "Jean-Paul":

http://translate.google.com/#en|fr|John%20Paul


[Updated on: Mon, 18 April 2011 11:13]

Report message to a moderator

Re: Code to Convert English Names to Arabic [message #503671 is a reply to message #503645] Tue, 19 April 2011 00:03 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hey Barbara,

I don't think the same. I frequently used google translater for my German class assignments (where I need to convert German to English), and my teacher always caught me, because it does the literal translation. It also converts the name to their respective translation in that language. If you don't believe just see that.

http:// translate.google.com/#hi|en|%E0%A4%95%E0%A4%B2%E0%A5%8D%E0%A4%AA%E0%A4%A8%E0%A4%BE%20%E0%A4%97%E0%A5%81%E0%A4%AA%E0%A5%8D%E0%A4%A4%E0 %A4%BE%20%20

Above link will translate name 'Kalpana Gupta' in Hindi to 'Imagine Gupta' in English, where 'Imagine' is the literal meaning of 'Kalpana'. In other words, Google translator is a dumb translator. And I can't believe on that for some business purpose applications.

Regards,
Manu
Re: Code to Convert English Names to Arabic [message #503673 is a reply to message #503671] Tue, 19 April 2011 00:18 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
No automated translator can be perfect, but most of them are better than no translation. Also, it is debatable whether such name translations are appropriate or not. In one place that I worked, when speaking Spanish, we referred to Mister Green as Señor Verde.

Re: Code to Convert English Names to Arabic [message #503696 is a reply to message #503645] Tue, 19 April 2011 01:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
Also note the conversion of the English "John Paul" to the French "Jean-Paul":

But the translation from french to english of Jean-Paul is still Jean-Paul. Strange...

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503707 is a reply to message #503696] Tue, 19 April 2011 01:46 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
But translation from french to english of JeanPaul is "John Paul"

"-" makes the difference on Both languages.

Sriram
Re: Code to Convert English Names to Arabic [message #503710 is a reply to message #503707] Tue, 19 April 2011 01:55 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
JeanPaul does not exist in french.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503716 is a reply to message #503710] Tue, 19 April 2011 02:08 Go to previous messageGo to next message
ramoradba
Messages: 2457
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
I am talking about "Google translation"

http://translate.google.co.in/?hl=en&tab=wT#fr|en|JeanPaul

Both sounds as "Johnpaul" you can listen Smile

Sriram
Re: Code to Convert English Names to Arabic [message #503763 is a reply to message #503716] Tue, 19 April 2011 10:01 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hi All,

A lot of discussion on Google Translator. Well, as I earlier said that we can't use it in Business Applications. One can attach a POLL here for opinios about automatic translators.

Well, suppose if we stick to use that how we will integrate it with Oracle for translation?

[EDIT]

I just saw the post
Using internet translators from Oracle

Syakobson and Barbara discussed something over there, but I am unable to execute their codes, as I don't know head and tail of that code (means I am totally unaware of that package). Its giving the following error that its not declared. From where to install that package?

PLS-00201: identifier 'DBMS_NETWORK_ACL_ADMIN.CREATE_ACL' must be declared
PLS-00201: identifier 'DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL' must be declared


and '&' sign in url also causing some problem...

Thanks,
Manu

[Updated on: Tue, 19 April 2011 10:29]

Report message to a moderator

Re: Code to Convert English Names to Arabic [message #503765 is a reply to message #503763] Tue, 19 April 2011 10:29 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
Its giving the following error that its not declared. From where to install that package?

This is a 11g package so you have not and do not need it.

Quote:
and '&' sign in url also causing some problem...

"set define off" will remove them.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503770 is a reply to message #503765] Tue, 19 April 2011 11:33 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hi,

Its good, I never though that this can happen. Smile

Its working for some character-sets, but not working for English to Hindi Translation. How to enable Hindi character set, and where?

Thanks,
Manu
Re: Code to Convert English Names to Arabic [message #503772 is a reply to message #503770] Tue, 19 April 2011 11:51 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Your database character set must be AL32UTF8, your OS must suppport it and your client program too.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503774 is a reply to message #503772] Tue, 19 April 2011 12:09 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

I got the following error while attempting to change my character set-

SQL> connect system/manager
Connected.
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
ALTER DATABASE CHARACTER SET AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set


Thanks,
Manu
Re: Code to Convert English Names to Arabic [message #503776 is a reply to message #503774] Tue, 19 April 2011 12:14 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
The recommended solution is to CREATE DATABASE with the desired characterset.
expdp/impdp between original DB & new DB
Re: Code to Convert English Names to Arabic [message #503778 is a reply to message #503774] Tue, 19 April 2011 12:19 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
manubatham20 wrote on Tue, 19 April 2011 19:09
I got the following error while attempting to change my character set-

SQL> connect system/manager
Connected.
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
ALTER DATABASE CHARACTER SET AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set


Thanks,
Manu

Of course and this is explained in the ALTER DATABASE statement page in SQL Reference.
ALWAYS read the instructions and restrictions BEFORE using a statement.

ORA-12712: new character set must be a superset of old character set
 *Cause: When you ALTER DATABASE ... CHARACTER SET, the new
           character set must be a superset of the old character set.
           For example, WE8ISO8859P1 is not a superset of the WE8DEC.
 *Action: Specify a superset character set.


Regards
Michel

Re: Code to Convert English Names to Arabic [message #503787 is a reply to message #503778] Tue, 19 April 2011 12:58 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hi Michel,

I am currently using Oracle 10.2.0.3 and my character set is as follows-

SQL> SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET' ;

VALUE$
--------------------------------------------------------------------

WE8MSWIN1252


I am unable to alter the database character set as the character set I am using is already the super set of the character set that I want to use, am I right?


SQL> connect system/manager
Connected.
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
ALTER DATABASE CHARACTER SET AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set



As far as client is concerned, I tried the below-

SQL> select translation('I','HI','EN') from dual;
ERROR:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00217: invalid character 2350 (U+092E)
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at "SCOTT.TRANSLATION", line 41
ORA-06512: at line 1


on sqlplus on command prompt and by opening isqlplus on Opera.

I think, Opera supports Hindi, as I am able to see Google Translations for Hindi on Opera.

So why this error, does my OS doesn't support that Character Set or what?

Many Thanks,
Manu

[Updated on: Tue, 19 April 2011 12:59]

Report message to a moderator

Re: Code to Convert English Names to Arabic [message #503788 is a reply to message #503787] Tue, 19 April 2011 13:03 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
"translation" is NOT an Oracle procedure, it is one of yours. Check its code.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503789 is a reply to message #503788] Tue, 19 April 2011 13:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
I am unable to alter the database character set as the character set I am using is already the super set of the character set that I want to use, am I right?

You are unable to ALTER the character set because AL32UTF8 is NOT a strict super set of your current one.
AL32UTF8 is a strict super set of no character set but US7ASCII.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503790 is a reply to message #503788] Tue, 19 April 2011 13:06 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hi,

Sorry I forget to mention, 'Translation' is the same function defined in post Using internet translators from Oracle by Barbara.

I checked it for German, and its working correctly.

Thanks,
Manu
Re: Code to Convert English Names to Arabic [message #503791 is a reply to message #503790] Tue, 19 April 2011 13:08 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Barbara's function has only 23 lines so can't have an error at line 41.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503792 is a reply to message #503791] Tue, 19 April 2011 13:11 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Ufffff, I am not telling lie (May be my Computer fed up)... I think after compilation 41 line or something else. If you don't believe, just check at your end.

Please refer to the file attached.

Thanks,
Manu
  • Attachment: translate.txt
    (Size: 2.25KB, Downloaded 1470 times)

[Updated on: Tue, 19 April 2011 13:24]

Report message to a moderator

Re: Code to Convert English Names to Arabic [message #503794 is a reply to message #503792] Tue, 19 April 2011 13:33 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
What the file is supposeed to show?

Use SQL*Plus and copy and paste the whole session including the function creation and the execution with the error (formated of course).

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503796 is a reply to message #503794] Tue, 19 April 2011 13:39 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Below is my SQL session:

SQL> set define off
SQL> create or replace function translation
  2   (p_words in clob,  -- words to be translated
  3    p_to  in varchar2 default 'de', -- language to translate to (German)
  4    p_from in varchar2 default 'en') -- language to translate from (English)
  5                                          -- ar = Arabic
  6                                          -- en = English
  7                                          -- es = Spanish
  8                                          -- fr = French
  9  return clob
 10  as
 11       l_res        clob;
 12       l_words      clob;
 13     begin
 14       l_res := httpuritype
 15                   ('http://translate.google.com/?hl=' ||
 16                    p_from || '&layout=1&eotf=1&sl=' || p_from ||
 17                    '&tl=' || p_to || '&text=' ||
 18                    utl_url.escape (p_words) || '#').getclob();
 19       l_res := substr (l_res, instr (l_res, '<span title="' || p_words || '"'));
 20       l_res := substr (l_res, 1, instr (l_res, '</span>') + 6);
 21       l_words := XmlType (l_res).extract ('/span/text()').getStringVal();
 22       return l_words;
 23  end translation;
 24  /

Function created.

SQL> show errors
No errors.
SQL> select translation ('cats and dogs') from dual;

TRANSLATION('CATSANDDOGS')                                                      
--------------------------------------------------------------------------------
Katzen und Hunde                                                                

SQL> select translation ('I Love You','de','en') from dual;

TRANSLATION('ILOVEYOU','DE','EN')                                               
--------------------------------------------------------------------------------
Ich liebe dich                                                                  

SQL> select translation ('I Love You','hi','en') from dual;
ERROR:
ORA-31011: XML parsing failed 
ORA-19202: Error occurred in XML processing 
LPX-00217: invalid character 2350 (U+092E) 
Error at line 1 
ORA-06512: at "SYS.XMLTYPE", line 254 
ORA-06512: at "SCOTT.TRANSLATION", line 21 
ORA-06512: at line 1 



no rows selected

SQL> spool off


Regards,
Manu
Re: Code to Convert English Names to Arabic [message #503798 is a reply to message #503796] Tue, 19 April 2011 13:50 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
00217, 00000, "invalid character ~1u (~2x)"
// *Cause: An invalid Unicode character was found.
// *Action: Use only characters allowed by the XML specification.
Re: Code to Convert English Names to Arabic [message #503803 is a reply to message #503798] Tue, 19 April 2011 14:29 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Sad, It means Hindi character set is not allowed in XML...

Regards,
Manu
Re: Code to Convert English Names to Arabic [message #503808 is a reply to message #503803] Tue, 19 April 2011 14:50 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
If the Hindi character set is not allowed in XML, then you could substitute the code using regexp_substr that Solomon provided in the other thread for the xml in the function that I provided as demonstrated below. Please try it and let us know if it works with Hindi.

SCOTT@orcl_11gR2> create or replace function translation
  2    (p_words in clob,		  -- words to be translated
  3  	p_to	in varchar2 default 'ar', -- language to translate to
  4  	p_from	in varchar2 default 'en') -- language to translate from
  5  					  -- ar = Arabic
  6  					  -- en = English
  7  					  -- es = Spanish
  8  					  -- fr = French
  9    return	   clob
 10  as
 11    l_res	   clob;
 12    l_words	   clob;
 13  begin
 14    l_res := httpuritype
 15  		  ('http://translate.google.com/?hl=' ||
 16  		   p_from || '&layout=1&eotf=1&sl=' || p_from ||
 17  		   '&tl=' || p_to || '&text=' ||
 18  		   utl_url.escape (p_words) || '#').getclob();
 19    l_words :=  regexp_substr
 20  		 (l_res,
 21  		  '<span id=result_box class="short_text"><span[^>]*>(.*)</span></span>',
 22  		  1, 1, 'i', 1);
 23    return l_words;
 24  end translation;
 25  /

Function created.

SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'es') from dual
  2  /

TRANSLATION('CATSANDDOGS','ES')
--------------------------------------------------------------------------------
gatos y perros

1 row selected.

SCOTT@orcl_11gR2> select translation ('cats and dogs', 'fr') from dual
  2  /

TRANSLATION('CATSANDDOGS','FR')
--------------------------------------------------------------------------------
les chats et les chiens

1 row selected.

SCOTT@orcl_11gR2> select translation ('cats and dogs', 'de') from dual
  2  /

TRANSLATION('CATSANDDOGS','DE')
--------------------------------------------------------------------------------
Katzen und Hunde

1 row selected.

SCOTT@orcl_11gR2> 

Re: Code to Convert English Names to Arabic [message #503810 is a reply to message #503808] Tue, 19 April 2011 14:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Solomon's code works only in 11g, OP is in 10g.
But it is not hard to make it work in 10g.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503812 is a reply to message #503810] Tue, 19 April 2011 15:04 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
Michel Cadot wrote on Tue, 19 April 2011 12:54

Solomon's code works only in 11g, OP is in 10g.


Are you sure? Regexp_substr was available in 10g. The ACL stuff is required in 11g, but not needed in 10g. In 10g, you just leave that part out.


Using the latest function that I posted above, I ran:

select translation ('I love you.', 'HI', 'EN') from dual
/

and got:

मैं तुमसे प्यार करता हूँ

When I copied and pasted that into google translate to translate it back to English, I got, "I love you." as seen in the link below.

http://translate.google.com/#hi|en|%E0%A4%AE%E0%A5%88%E0%A4%82%20%E0%A4%A4%E0%A5%81%E0%A4%AE%E0%A4%B8%E0%A5%87%20%E0%A4%AA%E0%A5%8D%E 0%A4%AF%E0%A4%BE%E0%A4%B0%20%E0%A4%95%E0%A4%B0%E0%A4%A4%E0%A4%BE%20%E0%A4%B9%E0%A5%82%E0%A4%81

[Updated on: Tue, 19 April 2011 15:05]

Report message to a moderator

Re: Code to Convert English Names to Arabic [message #503814 is a reply to message #503812] Tue, 19 April 2011 15:16 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
Substituting Solomon's code that uses regexp_substr for the xml in the function seems to work better with other character sets. Although the result in other character sets displays on my system as numbers and ampersands, when copied and pasted onto this site, it displays in the proper character set.

SCOTT@orcl_11gR2> create or replace function translation
  2    (p_words in clob,		  -- words to be translated
  3  	p_to	in varchar2 default 'ar', -- language to translate to
  4  	p_from	in varchar2 default 'en') -- language to translate from
  5  					  -- ar = Arabic
  6  					  -- en = English
  7  					  -- es = Spanish
  8  					  -- fr = French
  9    return	   clob
 10  as
 11    l_res	   clob;
 12    l_words	   clob;
 13  begin
 14    l_res := httpuritype
 15  		  ('http://translate.google.com/?hl=' ||
 16  		   p_from || '&layout=1&eotf=1&sl=' || p_from ||
 17  		   '&tl=' || p_to || '&text=' ||
 18  		   utl_url.escape (p_words) || '#').getclob();
 19    l_words :=  regexp_substr
 20  		 (l_res,
 21  		  '<span id=result_box class="short_text"><span[^>]*>(.*)</span></span>',
 22  		  1, 1, 'i', 1);
 23    return l_words;
 24  end translation;
 25  /

Function created.

SCOTT@orcl_11gR2> show errors
No errors.


SCOTT@orcl_11gR2> select translation ('I love you.', 'HI', 'EN') from dual
  2  /

TRANSLATION('ILOVEYOU.','HI','EN')
--------------------------------------------------------------------------------
मैं तुम्हें प्यार करता हूँ.


1 row selected.

SCOTT@orcl_11gR2>


Re: Code to Convert English Names to Arabic [message #503820 is a reply to message #503814] Tue, 19 April 2011 22:23 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hi Barbara,

Many thanks for your efforts. Your post shows that its correct translation. But the function regexp_substr you used has the different signatures than regexp_substr function in Oracle 10g.

See the below-
In Oracle 11g
http://download.oracle.com/docs/cd/E14072_01/server.112/e10592/img/regexp_substr.gif

In Oracle 10g
http://download.oracle.com/docs/cd/B13789_01/server.101/b10759/regexp_substr.gif

I am unable to modify your function, as I am not good in Regular Expressions. I don't know where to change. The regexp_substr you used, can it be converted according to Oracle 10g.

Many Thanks,
Manu
Re: Code to Convert English Names to Arabic [message #503824 is a reply to message #503820] Tue, 19 April 2011 23:35 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
You could just use substr and instr instead of regexp_substr, as shown below.

SCOTT@orcl_11gR2> set define off
SCOTT@orcl_11gR2> create or replace function translation
  2    (p_words in clob,		  -- words to be translated
  3  	p_to	in varchar2 default 'ar', -- language to translate to
  4  	p_from	in varchar2 default 'en') -- language to translate from
  5  					  -- ar = Arabic
  6  					  -- de = German (Deutsch)
  7  					  -- en = English
  8  					  -- es = Spanish (Español)
  9  					  -- fr = French (Français)
 10    return	   clob
 11  as
 12    l_words	   clob;
 13  begin
 14    l_words := httpuritype
 15  		  ('http://translate.google.com/?hl=' ||
 16  		   p_from || '&layout=1&eotf=1&sl=' || p_from ||
 17  		   '&tl=' || p_to || '&text=' ||
 18  		   utl_url.escape (p_words) || '#').getclob();
 19    l_words := substr (l_words, instr (l_words, '<span id=result_box class="short_text"><span'));
 20    l_words := substr (l_words, instr (l_words, '>') + 1);
 21    l_words := substr (l_words, instr (l_words, '>') + 1);
 22    l_words := substr (l_words, 1, instr (l_words, '</span></span>') - 1);
 23    return l_words;
 24  end translation;
 25  /

Function created.

SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'es') from dual
  2  /

TRANSLATION('CATSANDDOGS','ES')
--------------------------------------------------------------------------------
gatos y perros

1 row selected.

SCOTT@orcl_11gR2> select translation ('cats and dogs', 'fr') from dual
  2  /

TRANSLATION('CATSANDDOGS','FR')
--------------------------------------------------------------------------------
les chats et les chiens

1 row selected.

SCOTT@orcl_11gR2> select translation ('cats and dogs', 'de') from dual
  2  /

TRANSLATION('CATSANDDOGS','DE')
--------------------------------------------------------------------------------
Katzen und Hunde

1 row selected.

SCOTT@orcl_11gR2> select translation ('I love you.', 'HI', 'EN') from dual
  2  /

TRANSLATION('ILOVEYOU.','HI','EN')
--------------------------------------------------------------------------------
मैं तुम्हें प्यार करता हूँ.


1 row selected.

SCOTT@orcl_11gR2>

Re: Code to Convert English Names to Arabic [message #503831 is a reply to message #503824] Wed, 20 April 2011 00:45 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Hi,

Thanks, now I can execute the function for Hindi as well. But its showing me output as follows-

SQL> select translation ('cats and dogs','hi','en') from dual;

TRANSLATION('CATSANDDOGS','HI','EN')                                            
----------------------------------------------------------------
बिल्लियों और &   <-- I wrote here some number with & like & # 2348; & # 2367 
(I putted space between & and # and number because 
its automatically converting them to characters here.)


I am getting some numbers followed by &# sign, but when I posting those numbers here, Its automatically gets converting into Hindi characters. I just want to know, which settings needs to be changed.

Thanks,
Manu

[Updated on: Wed, 20 April 2011 00:55] by Moderator

Report message to a moderator

Re: Code to Convert English Names to Arabic [message #503836 is a reply to message #503831] Wed, 20 April 2011 00:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
There is no possible change.
The site returns HTML code which is interpreted by any browser but not by SQL*Plus which returns raw data as you send it.

Regards
Michel
Re: Code to Convert English Names to Arabic [message #503913 is a reply to message #503836] Wed, 20 April 2011 06:22 Go to previous messageGo to previous message
shanie
Messages: 118
Registered: January 2011
Senior Member
I am using database 1og

Though the function is created but I got errors
while running the statement
select translation ('cats and dogs') from dual;
ERROR:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1674
ORA-12541: TNS:no listener
ORA-06512: at "SYS.HTTPURITYPE", line 34
ORA-06512: at "SYS.TRANSLATION", line 14
ORA-06512: at line 1


set define off
create or replace function translation
 (p_words in clob,  -- words to be translated
  p_to  in varchar2 default 'de', -- language to translate to (German)
  p_from in varchar2 default 'en') -- language to translate from (English)
                                        -- ar = Arabic
                                        -- en = English
                                        -- es = Spanish
                                        -- fr = French
return clob
as
     l_res        clob;
     l_words      clob;
   begin
     l_res := httpuritype
                 ('http://translate.google.com/?hl=' ||
                  p_from || '&layout=1&eotf=1&sl=' || p_from ||
                  '&tl=' || p_to || '&text=' ||
                  utl_url.escape (p_words) || '#').getclob();
     l_res := substr (l_res, instr (l_res, '<span title="' || p_words || '"'));
     l_res := substr (l_res, 1, instr (l_res, '</span>') + 6);
     l_words := XmlType (l_res).extract ('/span/text()').getStringVal();
     return l_words;
end translation;
/
 
Function created.


Regards
Shanie
Previous Topic: Net Manager
Next Topic: cursor not fetching values
Goto Forum:
  


Current Time: Fri May 16 06:01:53 CDT 2025