hb_translate() - Conversion from ASCII - latin 850 to UTF-8 (latin and cyrillic) plz hlp

1,399 views
Skip to first unread message

Zoran Sibinovic

unread,
May 11, 2011, 6:41:45 AM5/11/11
to Harbour Developers
Hi

I have an URGENT problem of translation between formats in a text
files

I need to translate/convert strings from ASCII - latin 850 to UTF-8
(cyrillic)
I found the hb_translate() function, but cant find adequate parameters
to get what I need.

If someone can help ... plz

thanks in advance

Zoran

Jacek Kubica

unread,
May 11, 2011, 9:15:33 AM5/11/11
to Zoran Sibinovic
Hello Zoran,

Wednesday, May 11, 2011, 12:41:45 PM, you wrote:

ZS> I have an URGENT problem of translation between formats in a text
ZS> files

ZS> I need to translate/convert strings from ASCII - latin 850 to UTF-8
ZS> (cyrillic)
ZS> I found the hb_translate() function, but cant find adequate parameters
ZS> to get what I need.
ZS> If someone can help ... plz

Try HB_TRANSLATE(cString,"CP850","UTF8") => cUTFString


--
Best regards,
Jacek Kubica

Viktor Szakáts

unread,
May 11, 2011, 9:32:38 AM5/11/11
to harbou...@googlegroups.com
> ZS> I need to translate/convert strings from ASCII - latin 850 to UTF-8
> ZS> (cyrillic)
> ZS> I found the hb_translate() function, but cant find adequate parameters
> ZS> to get what I need.
> ZS> If someone can help ... plz
>
> Try HB_TRANSLATE(cString,"CP850","UTF8") => cUTFString

In Harbour we don't have real codepages (to my deep regret)
as "CP850", so you need to select a Clipper-like alternative,
which is tied to a language/culture:
HB_TRANSLATE( cString, "ES850", "UTF8" )

Though latin to cyrillic doesn't make much sense in the
context of CP conversion.

Viktor

Zoran Sibinovic

unread,
May 12, 2011, 2:21:32 AM5/12/11
to Harbour Developers
Thanks Victor

I have tried your code and
works 100% for basic letters - HB_TRANSLATE( cString, "ES850",
"UTF8" )

but not totally for special characters how you can see below

original string [ - ] - \ - ^ - @ - { - } - | - ~ - ` -
DJ - dj - D@ - d`

expected Ш - Ћ -Ђ - Ч - Ж - ш - ћ - ђ - ч - ж - Ђ
- ђ - Џ - џ

HB_TRANSLATE result Ш - Ћ - Ђ - Ч - Ж - { - } - | - ~ - ` - Ђ - dj - Џ
- d`

piece of luck that in this moment I need only upper letters and the
spec char I will translate them with a help of the STRTRAN() function
and notepad.

Another "handly" method that I found is to write the alphabet in
notepad (local latin or cyrillic) and save it as an utf8 .txt file.
Then read and insert the letters signs in my code through my .prg
editor (OEM view) where every letter of my wanted-to-convert string
will be replaced with STRTRAN().

Works 100% in my case, with some acrobatic moves. I think that can
work with other locals too.

Zoran
Reply all
Reply to author
Forward
0 new messages