| Lurk all you'd like, but why not register and post some pics? Registering also makes it easier to find the good stuff. Need help? |
|
|||||||
| Register | FAQ | Shooters | Calendar | Reviews | Tutorials | Gallery | Books | Search | Today's Posts | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Tutorial - creating a bilingual site
Had some fellow dgrinners over here helping me in creating my dual language site. Now I did create a little tutorial out of it, because I already got 2 mails asking for some help in getting this done (Michael and James
).It all got a bit technical, so if you've got any problems or questions, feel free to ask! If someone got solutions for the problems I listed at the end, I would be very glad! Here we go: Copy this into your Javascript section: Code:
//-------start of StyleSheetSwitch Code // add your own reliable webspace where you'll have to put lang1_file and lang2_file // don't add a '/' at the end of the server address - this is done later!! var _g_myServer = "http://your-webspace.com/path-to-lang-css-files"; var lang1 = "english"; var lang1_file = "eng.css"; var lang2 = "german"; var lang2_file = "ger.css"; function readCookieStyle(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function createCookieStyle(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function setSheet(lang) { createCookieStyle("style", lang, 365); location.reload(); } function includeBrowserCSS() { document.writeln("<style type=\"text/css\">"); var lang; var lang_file; var cookie = readCookieStyle("style"); if (cookie == lang1) { lang = lang1; lang_file = lang1_file; } if (cookie == lang2) { lang = lang2; lang_file = lang2_file; } // when no cookie is found, use lang1 as standard language if (cookie != lang1 && cookie != lang2) { lang = lang1; lang_file = lang1_file; } document.writeln("@import url("+_g_myServer+"/"+lang_file+");"); document.writeln("</style>"); createCookieStyle("style", lang, 365); } //------ end of StyleSheetSwitch Code The following part launches the whole script and now goes into the head-tag (if you have the following lines still in your header-section please remove them from their) New: added <noscript>-tag that sets a standard language for visitors without javascript-support. Just replace my sample link with the full address to the language-css-file of your choice (in my case I set the default to English with eng.css). Code:
<script language="javascript"> includeBrowserCSS(); </script> <noscript><link rel="stylesheet" type="text/css" href="http://your-webspace.com/path-to-lang-css-files/eng.css"></noscript> Code:
<a href="#top" onclick="setSheet(lang1);return false;">English</a> <a href="#top" onclick="setSheet(lang2);return false;">Deutsch</a> eng.css: Code:
.ger {display:none;}
Code:
.eng {display:none;}
After you've done all this you should be able to add bi-lingual captions, gallery descriptions and a bio. This is done according to a scheme where both languages are surrounded by a span-tag and only one of the tags is displayed according to the user's language choice. It goes like this: <html>Text that is displayed independent from any language choice<span class="ger"> Deutscher Text - German text</span><span class="eng"> English text - notice the space after the beginning span-tag: It's to separate the language specific text from the language independent text.</span></html> Problems: - doesn't work in previewed descriptions on homepage and category navigation, because html is filtered there - also doesn't work in traditional view, smugmaps and full screen slideshow, because html is filtered out of the caption. This displays both languages. - alt-tag (when image can't be displayed) always contains both languages (html is filtered) - both languages are shown when external server isn't availiable Hope this is useful for some of you. It might be even possible to simply add some more languages. In thinking about it I didn't see any problems, but there might occur some in the actual realization. If someone's interested, we could work this out together. Sebastian EDIT: Updated the script according to the new customization options of smugmug from 11/27 (see big, bold text in my post). No more need for CSS-hacks - it's now according to the standards. EDIT2: Include support for browser's having javascript disabled - instead of seeing both languages they get one default language set by you!
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) Last edited by rainforest1155; May-20-2006 at 03:08 AM. Reason: Added support for browser's without javascript! |
|
|
|
|
|
#2 |
|
I � Unicode
Join Date: Feb 2005
Location: Dover, DE
Posts: 7,059
|
Does this work anymore considering that you cannot hack the CSS box to insert stuff into the header? If so, how do you get around it?
__________________
Y'all don't want to hear me, you just want to dance. http://photos.mikelanestudios.com/ |
|
|
|
|
|
#3 | |
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Quote:
Sebastian
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) |
|
|
|
|
|
|
#4 | |
|
Happy Snapper
Join Date: Oct 2004
Location: Boston, MA 02111 (USA)
Posts: 1,272
|
Quote:
The 'illegal' parts are adding <link> elements (acting as links to external CSSs), through javascript, after the <body> link as been opened. But, i guess, as long as one does this before any other (visual) element within the <body> tag has been started/opened, it is fine.
__________________
I can't grasp the notion of time. When I hear the earth will melt into the sun, in two billion years, all I can think is: "Will that be on a Monday?" ========================== http://www.streetsofboston.com http://blog.antonspaans.com |
|
|
|
|
|
|
#5 | |
|
Happy Snapper
Join Date: Oct 2004
Location: Boston, MA 02111 (USA)
Posts: 1,272
|
Quote:
First the page is loaded only using the style-sheets specified inside the <HEAD> tag! You'll see this first (default smugmug style). Then a fraction of a second later, the CSS is loaded from the 'illegal' spot and the new CSS selectors will be applied and the page looks OK. But this 'flashing' effect is bothersome!
__________________
I can't grasp the notion of time. When I hear the earth will melt into the sun, in two billion years, all I can think is: "Will that be on a Monday?" ========================== http://www.streetsofboston.com http://blog.antonspaans.com |
|
|
|
|
|
|
#6 | |
|
Happy Snapper
Join Date: Oct 2004
Location: Boston, MA 02111 (USA)
Posts: 1,272
|
Quote:
The page goes white for a fraction of a second before redrawing the page as it should be.
__________________
I can't grasp the notion of time. When I hear the earth will melt into the sun, in two billion years, all I can think is: "Will that be on a Monday?" ========================== http://www.streetsofboston.com http://blog.antonspaans.com |
|
|
|
|
|
|
#7 | |
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Quote:
I also checked your site...it's fine. I'm on Win2000 - maybe that's a factor. I remember setting my Opera to that it should reveal itself as Opera and not as IE which was set after installing it. Thanks for taking the time to check this! Sebastian
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) |
|
|
|
|
|
|
#8 | |
|
Happy Snapper
Join Date: Oct 2004
Location: Boston, MA 02111 (USA)
Posts: 1,272
|
Quote:
I think the biggest problem is this: When the browser encounters an open <BODY> tag, it draws a background. If no CSS yet loaded, the background is white. If a CSS is loaded, the style of the BODY is applied (including any background images). If the CSS is loaded before the BODY tag --> No 'flashing'. If the CSS is loaded after opening the BODY tag --> 'Flashing'. Also, loading a javascript file after the open <BODY> tag takes a little extra time --> The 'flash' last longer before the BODY (and the rest) draws itself correctly. By adding my main CSS and main JavaScript to the co-branding fields instead, the CSS and JavaScripts are loaded in the HEAD, before the BODY --> no more flashing.
__________________
I can't grasp the notion of time. When I hear the earth will melt into the sun, in two billion years, all I can think is: "Will that be on a Monday?" ========================== http://www.streetsofboston.com http://blog.antonspaans.com |
|
|
|
|
|
|
#9 | |
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Quote:
Sebastian
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) |
|
|
|
|
|
|
#10 |
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Smugmug update 11/27
Updated the script according to the new customization options of smugmug from 11/27 (see big, bold text in my first post). No more need for CSS-hacks - it's now according to the standards.
Have fun, Sebastian
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) |
|
|
|
|
|
#11 | |
|
Happy Snapper
Join Date: Oct 2004
Location: Boston, MA 02111 (USA)
Posts: 1,272
|
Quote:
__________________
I can't grasp the notion of time. When I hear the earth will melt into the sun, in two billion years, all I can think is: "Will that be on a Monday?" ========================== http://www.streetsofboston.com http://blog.antonspaans.com |
|
|
|
|
|
|
#12 | |
|
I � Unicode
Join Date: Feb 2005
Location: Dover, DE
Posts: 7,059
|
Quote:
![]() ![]()
__________________
Y'all don't want to hear me, you just want to dance. http://photos.mikelanestudios.com/ |
|
|
|
|
|
|
#13 | ||
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Quote:
I guess this leaves me just this option: Triple Hip-Hip-Horaaay to our favorite support team!! Sebastian
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) |
||
|
|
|
|
|
#14 |
|
Big grins
Join Date: Apr 2004
Location: Finland
Posts: 71
|
Really nice
Hi all
I'm following your code and trying to implement the same in my site now that I have a power account. I want to thank for your work, it is really interesting. One thing. Is it possible to change the other text in the page as well? I mean I'd like in my bilingual (Spanish and English) site to be able to use (Gallery/Galerķa) when appropriate. Any ideas Carlos |
|
|
|
|
|
#15 | |
|
with a SmugMug Her0es touch
Join Date: Jun 2004
Location: Leipzig, Germany
Posts: 2,631
|
Quote:
maybe this could be done using some more JavaScript, but I guess it's only possible after the page has loaded. That means the standard English words would be visible for a second and then replaced by Spanish. Also it's kind of hard to exactly specify the words to replace, because there's no specific tag to mark them. This is how the source code looks for the 'Gallery Pages' in smugmug view: <div class="pageNav leftColumn nav"><span class="title">gallery pages:... Maybe one could search for pageNav-class + title-class and if there's a string called 'gallery page' replace it with 'galerķa paginas'. I don't know if this would work for all the styles. Then you would have to look at the source of all other English words and try to find tags that are connected to them. Or you might simply do a full text search in the whole document for all words to replace without the need to check for tags. Would that be slower or perhaps even faster?? ![]() Just throwing in some ideas - I've got no clue on the programming itself. Any JavaScripter got some ideas on the realization? ![]() Glad my tutorial was of some use for you! Maybe you can share your site with us - I would like to see how it turned out on your site. It's always nice to see how others implemented it. ![]() Sebastian
__________________
look on the bright side http://www.SebastianHosche.com (smugmug name: rainforest1155) |
|
|
|
|
|
|
#16 |
|
Big grins
Join Date: Apr 2004
Location: Finland
Posts: 71
|
I'm gonna try
Hi
I'll try to create this kind of bilingual site. I'm not very convinced it is possible without some markets but let's see. I'm a programmer btu I haven't done JavaScript for a while Carlos
__________________
http://tibu.smugmug.com |
|
|
|
|
|
#17 | |
|
I � Unicode
Join Date: Feb 2005
Location: Dover, DE
Posts: 7,059
|
Quote:
__________________
Y'all don't want to hear me, you just want to dance. http://photos.mikelanestudios.com/ |
|
|
|
|
|
|
#18 |
|
Big grins
Join Date: Apr 2004
Location: Finland
Posts: 71
|
My mistake
Hi
I was meaning markers (not markets), I'm crossing nomenclature from other project I'm working on :-) Carlos
__________________
http://tibu.smugmug.com |
|
|
|
|
|
#19 | |
|
I � Unicode
Join Date: Feb 2005
Location: Dover, DE
Posts: 7,059
|
Quote:
__________________
Y'all don't want to hear me, you just want to dance. http://photos.mikelanestudios.com/ |
|
|
|
|
|
|
#20 |
|
Big grins
Join Date: Apr 2004
Location: Finland
Posts: 71
|
Using the DOM
Hi
Actually there is a "simple" way to do it. You could manipulate the DOM tree, find the elements you want and replace the text by a transalted version. What I'm afraid is that finding the elements is difficult since they don't have ids. So you have to identify them by position and that will certainly make the script very brittle. For instance to change the "help" text on the top corner I used Code:
var headerDiv = document.getElementById("toolbar");
if (headerDiv) {
headerDiv.childNodes[5].firstChild.nodeValue = "Ayuda";
}
It would be much better that each element had an id. For example that the "help" html tag would be Code:
<a href="http://www.smugmug.com/help" class="nav" id="i18n.help">help</a> instead of <a href="http://www.smugmug.com/help" class="nav">help</a> I have still to check if this works properly everywhere and also link it to the original code that Sebastian created so that you could select what language to use Carlos
__________________
http://tibu.smugmug.com |
|
|
|
![]() |
| Tell The World! |
| Thread Tools | |
| Display Modes | |
|
|