YigalB Posted February 1, 2012 Share Posted February 1, 2012 Is there a recommended way to code in order to have a dual language support, especially when one is English (left to right), and the other is Hebrew (right to left)? Should I design every page twice or is there a ready made solution? Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/ Share on other sites More sharing options...
scootstah Posted February 1, 2012 Share Posted February 1, 2012 Read: http://www.w3.org/International/tutorials/bidi-xhtml/ Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313398 Share on other sites More sharing options...
YigalB Posted February 1, 2012 Author Share Posted February 1, 2012 Read: http://www.w3.org/International/tutorials/bidi-xhtml/ Thanks. It is useful. But the main challenge I have is how to approach the web site design when it could be used by R2L or by L2R users. Should I duplicated the pages? this will cause maintenance to be painful. Should I have a parameter which will indicate R2L or L2R and have many IF with in the pages? This will make the code less readable. Is there a recommended solution? Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313414 Share on other sites More sharing options...
ManiacDan Posted February 1, 2012 Share Posted February 1, 2012 You can set text direction in CSS, just make sure every span has a "directionable" class, then change that one line in your CSS. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313460 Share on other sites More sharing options...
scootstah Posted February 1, 2012 Share Posted February 1, 2012 Read: http://www.w3.org/International/tutorials/bidi-xhtml/ Thanks. It is useful. But the main challenge I have is how to approach the web site design when it could be used by R2L or by L2R users. Should I duplicated the pages? this will cause maintenance to be painful. Should I have a parameter which will indicate R2L or L2R and have many IF with in the pages? This will make the code less readable. Is there a recommended solution? If you generate the code with PHP then you can just set the dir attribute. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313481 Share on other sites More sharing options...
AyKay47 Posted February 1, 2012 Share Posted February 1, 2012 I would prefer to use CSS for this, as it makes the code a little more robust and easy to maintain. CSS has a property for this called the "direction" property which has three possible values: ltr (left to right, default), rtl (right to left) and inherit meaning it inherits the direction property from its parent element. As ManiacDan stated, a class for this can be made and be assigned to any text that you want this to affect. There are several ways to implement the ltr, rtl change as well. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313494 Share on other sites More sharing options...
YigalB Posted February 2, 2012 Author Share Posted February 2, 2012 I would prefer to use CSS for this, as it makes the code a little more robust and easy to maintain. CSS has a property for this called the "direction" property which has three possible values: ltr (left to right, default), rtl (right to left) and inherit meaning it inherits the direction property from its parent element. As ManiacDan stated, a class for this can be made and be assigned to any text that you want this to affect. There are several ways to implement the ltr, rtl change as well. Thanks. I like the idea, and I will try it. What about the text itself? For example, on a certain page I will need to display a content/ For example, write a "Hello" in case of L2R, or the same word in a different language R2L. Should I have many "if" statements in the code, so the server will send the right word according to the $direction variable? O Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313615 Share on other sites More sharing options...
AyKay47 Posted February 2, 2012 Share Posted February 2, 2012 Without seeing the logic in your code, it would be impossible to tell you exactly how you should implement this into your code. The method you provided could work, although it seems tedious to write many if statements. Again, without seeing how you are setting up the different language texts, it's hard to say. However something along the lines of determining what language the text is, and wrapping it in an element with the direction class dynamically is most likely what I would do. You can also detect the strings encoding using an mb function, mb_detect_encoding and act accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313657 Share on other sites More sharing options...
Adam Posted February 2, 2012 Share Posted February 2, 2012 Just give each text element the directional class, and at the top of your page have a very small in-line stylesheet that conditionally defines it as left to right, or right to left. Personally I would only define it if it's right to left. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313667 Share on other sites More sharing options...
ManiacDan Posted February 2, 2012 Share Posted February 2, 2012 What you need to do is wrap EVERY word in a "translate" function. For every piece of text on your website, instead of echoing it directly, echo tl("Hello!"); Then make a translation file that maps "Hello!" To "Hola!" And "Bonjour!" tr() will echo the proper one based on your language. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313696 Share on other sites More sharing options...
YigalB Posted February 2, 2012 Author Share Posted February 2, 2012 What you need to do is wrap EVERY word in a "translate" function. For every piece of text on your website, instead of echoing it directly, echo tl("Hello!"); Then make a translation file that maps "Hello!" To "Hola!" And "Bonjour!" tr() will echo the proper one based on your language. Good idea, but why to do in on word basis? why not sentence? Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313713 Share on other sites More sharing options...
Adam Posted February 2, 2012 Share Posted February 2, 2012 You would need to use sentences, otherwise there would be no context and it just wouldn't make sense. Paragraphs would be even better. I don't think Dan meant word quite so literally. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313714 Share on other sites More sharing options...
ManiacDan Posted February 2, 2012 Share Posted February 2, 2012 Right, that was an example. You do it on a "per text element" basis. "Hello!" is one. "This website copyright © 2012 by Some Guy International, all rights reserved" is another. Quote Link to comment https://forums.phpfreaks.com/topic/256199-dual-language-support-right-to-left-and-left-to-right/#findComment-1313735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.