SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Solved] Convert "Версия для печати" to "Контакты"

    I am trying to convert a string like this:

    Версия для печати

    Into Russian like this:

    Контакты

    Joomla CMS does this as the Russian language file is filled with the strange characters on the first line, but outputs the Russian characters on the 2nd line in the actual code.

    Any help will be much appreciated.
    Last edited by CT Internet; Nov 23, 2007 at 03:20. Reason: Added [solved] to subject
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's UTF-8 encoded text. Send a content-type header with your page, to specify the encoding. In PHP, you can do that with:
    PHP Code:
    header("Content-Type: text/html; encoding=utf-8"); 

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    That's UTF-8 encoded text.
    Actually, I don't know for sure that it's UTF-8 code. It's only a good guess on my behalf, since that's usually what it is, when it's not ISO-8859-1.

    Before you can convert a string, you need to figure out, which encoding it's currently in. So where did you get that string from?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hej Kyber tak for det! (English: Thanks!)

    But what I am looking for is a function or similar that will convert the encoded string to "Контакты"
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just found the function mb_detect_encoding("Âåðñèÿ äëÿ ïå÷àòè") and it returns that the encoding is ASCII
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried all of these conversions and none of them work.

    echo iconv("ASCII", "Windows-1251", "&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo iconv("ASCII", "UTF-8", "&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo iconv("Windows-1251", "UTF-8", "&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo iconv("Windows-1251", "ASCII", "&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo mb_convert_encoding("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;","Windows-1251","ASCII")."<br>";
    echo mb_detect_encoding("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo utf8_decode("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo utf8_encode("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;")."<br>";
    echo convert_cyr_string("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;","k","w")."<br />";
    echo convert_cyr_string("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;","i","w")."<br />";
    echo convert_cyr_string("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;","a","w")."<br />";
    echo convert_cyr_string("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;","d","w")."<br />";
    echo convert_cyr_string("&#194;&#229;&#240;&#241;&#232;&#255; &#228;&#235;&#255; &#239;&#229;&#247;&#224;&#242;&#232;","m","w")."<br />";

    I need to have the output as Windows-1251 as that is the encoding of the page. *sigh*

    Any help is appreciated!
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your string is in UTF-8, so if you want to convert it to windows-1251, you would need to do:
    PHP Code:
    iconv("UTF-8""CP1251""Версия для печати"); 
    If it's realistic to change, you would be wise to use UTF-8 as your encoding though, rather than windows-1251. You can not mix characters from iso-8859-1 with windows-1251, but UTF-8 contains all letters in those alphabets (and any other, for the matter) so you wouldn't get trouble mixing them.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HELP ME! I am going crazy!

    I have been looking through Joomla's code and all I can see is that they include a language file full of constant definitions like this:

    DEFINE('_CMN_FOLDER',"&#202;&#224;&#242;&#224;&#235;&#238;&#227;");
    DEFINE('_CMN_SUBFOLDER',"&#207;&#238;&#228;&#234;&#224;&#242;&#224;&#235;&#238;&#227;");
    DEFINE('_CMN_OPTIONAL',"&#205;&#229; &#238;&#225;&#255;&#231;&#224;&#242;&#229;&#235;&#252;&#237;&#238;");
    DEFINE('_CMN_REQUIRED',"&#206;&#225;&#255;&#231;&#224;&#242;&#229;&#235;&#252;&#237;&#238;");

    And then simply echo those onto a page with an encoding of "windows-1251".

    I have tried to copy the HTML from that page and echoed my own strings and they do not appear correctly.

    WHAT IS GOING ON?
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ohh - I was hoping your previous solution would have helped but it doesn't - thanks for trying though I REALLY appreciate it!

    Please try to see this page: http://www.medhead.com/test.php
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  10. #10
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The string is from a Joomla language file (in Russian) and when I run a mb_detect_encoding($str) it returns as ASCII
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  11. #11
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CT Internet View Post
    The string is from a Joomla language file
    And which encoding does Joomla use, when using this language? You can open a page and select the browser menu View > Character Encoding (In Firefox) to see which encoding, the page is interpreted in.

    Quote Originally Posted by CT Internet View Post
    when I run a mb_detect_encoding($str) it returns as ASCII
    You can't use mb_detect_encoding for anything here. It's just an algorithm, which makes a qualified guess on the encoding. It can't detect it with certainty, and ASCII basically means "unknown".

  12. #12
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh... turns out that Dreamweaver changed my content before uploading... stand by...
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  13. #13
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, so now my problem is to get Javascript (AJAX) to display the string as Windows-1251. Thanks for all your help!
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  14. #14
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you are right. It is UTF-8 encoded and needs to be displayed as windows-1251 to work. My original problem persists though - I am loading this through an AJAX call and inside a textarea and the content is showing as the UTF encoded string even though it is displayed on a windows-1251 encoded page. BUT I now have a better unserdtanding about it, and will try to solve this issue now. Thanks again for all your help!

    Du er sgu for genial! :-)
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  15. #15
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Note that XmlHttpRequest expects data to be UTF-8, so you should make sure it is. If it ends up in the document as gibberish, it's probably because you have encoded it twice. Most likely, you're using some sort of framework/library on the PHP side, which automatically encodes the string for you. You don't want this, in this case, because the string is already in UTF-8.

  16. #16
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more thing to note. When you have utf-8 encoded script and open it in editor as windows-1251, you get such records as you listed. I experienced this problem when I was migrating from writing scripts in win-1251 to utf-8.

  17. #17
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I got it all to work when I switched from the javaScript escape() function to the javascript encodeURIComponent() - that converted the string into a UTF encoded string when recieved by my PHP script (even without using urldecode()!) then all I had to do was add a header("Content-Type: text/html; charset=ASCII"); and then mb_convert_encoding($str,"CP1251","UTF-8"); in order to get the string back as "&#202;&#224;&#242;&#224;&#235;&#238;&#227;" for saving in the Joomla language file.

    Thanks for all the help and input!
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  18. #18
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool I need help with encoding on www.satilir.az

    If anybody knows how to fix this problem please let me know ASAP

    I cant switch between english and russian when i switch to russian i always have to encode each page.

    HELP HELP

  19. #19
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to put:

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />

    In the header of your document
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  20. #20
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or if that does not work then <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  21. #21
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks t2 all, i had the sam problems this the keywords
    on my site http://positon.com.ua/
    it looks like позитон and i didn't know how 2 repair it

  22. #22
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The meta tag is irrelevant, if you page is served by a web server, which sends content-type headers (Hint: Most web servers will). The reason is, that a meta tag is always overruled by a http-header. Make sure that your web server is sending the content-type header. In PHP, you do that with the function header

  23. #23
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but if PHP is not used.. i used only html and css on this web-site..

    it seems to mee that this problem is over... before that there was another site on this place wich was written on engine... seems to me that problem was in it...

    anyway thanks for everything... sorry about my poor english

  24. #24
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're not using PHP, then the page will be served by the webservers default for that file type. That is a web server configuration setting.
    In you case, the pages are served with the following headers:
    Code:
    HTTP/1.x 200 OK
    Server: nginx/0.5.12
    Date: Sun, 25 Nov 2007 12:55:47 GMT
    Content-Type: text/html; charset=windows-1251
    Connection: keep-alive
    Last-Modified: Fri, 23 Nov 2007 22:22:58 GMT
    Etag: "1986cb-140c-474752c2"
    Accept-Ranges: bytes
    Content-Length: 5132
    As you can see in the Content-Type header, the page is served as windows-1251, so that is what your content should be in. It doesn't hurt to put a meta tag, with the same information in there, but it won't have any effect either.

    You can use the LiveHTTPHeaders plugin for irefox, to inspect which headers, your web page is served with.

  25. #25
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •