• 0

How to make a HTML5/CSS3 website multilingual with 1 click?!


Question

Hello!

 

I'm not a webdesigner, noir a webdeveloper. But I'm making a little website, where I have template website, made of HTML5 + CSS3. My webhost does not support any PHP, and I was wondering if it's possible to make it multilingual with 1 click.

 

I had a little thoery/idea how it could work, but since I have not clue what HTML5 or CSS3 can do, I'm not sure if it's possible to do, anyway, here it goes:

 

The template has a index.html (which has all the text) and loads some .js and .css files for the animations and style.

 

(1) So, immediately my idea was, to replace all the text with a variable, that I store in a .xml/.lang file, where I define each "paragraph" that I have in my index.html. Make this xml file for all language that I have, for example I would have: english.lang (.xml) then german.lang (.xml) and so forth. Then I make a button (or little flags) in the index.html and if you click and english flag, the website replaces all text variables with the once stored in the English one, for German the other, and for the 3rd also. Is this possible, and if, how can I define the .xml/.lang file?

 

(2) My second idea was, to store the text in the ccs file and load the language as "profiles", make also little flags somewhere in the corner and then if 1 is clicked it changes the text shown, just as you make font decrease/increase size with CSS3.

 

(3) ...

 

That's all I had in mind and idea, but as sad....I have no f**** clue how to program the code for it, for me, logically it seam so easily to be done, but maybe in code it's a long walk. Help is much-much appreciated, or any other, more simple or easy idea too.

 

Thanks for reading. :)

17 answers to this question

Recommended Posts

  • 0

get a webhost that does support PHP and do that kind of things server side.

 

In theory, you could do what you are talking about, give every element on the page you want multilang an ID, make language files in JSON (easier to use in js than XML) and replace all the text with javascript. But it really is overly complex and not user friendly.

 

edit: some more explanation of your idea

 

give every element an ID and class, for example <h1 id="title" class="shouldtranslate">the title</h1>

 

go through all the elements with class shouldtranslate with jquery

 

$(".shouldtranslate").each(function()

{

 

//get the id

var id = $(this).attr("id");

 

//get the property in the json with that id and set it as the new content

 

$(this).text(mylanguagejsonobject[id]);

 

});

 

you json would look something like

 

{ title : "le titre" }

 

But as said, don't do that, it's not user friendly

  • 0
  On 17/07/2013 at 09:05, XerXis said:

get a webhost that does support PHP and do that kind of things server side.

 

In theory, you could do what you are talking about, give every element on the page you want multilang an ID, make language files in JSON (easier to use in js than XML) and replace all the text with javascript. But it really is overly complex and not user friendly.

 

Yup. That was my big fear, logically it seems sooooo easy to do and then to code it down, would be like a mess. I'm sad. :( Thou if you say JSON is easier, I will google around a bit, maybe I find something that helps me to start somewhere.

 

Sadly PHP server is not an option, don't want to spend money and something as tiny as this, just a personal website and my domain host simply does not provide PHP, only for "hard money" which I'm not going to spend.

  • 0
  On 17/07/2013 at 09:11, Class said:

Yup. That was my big fear, logically it seems sooooo easy to do and then to code it down, would be like a mess. I'm sad. :( Thou if you say JSON is easier, I will google around a bit, maybe I find something that helps me to start somewhere.

 

Sadly PHP server is not an option, don't want to spend money and something as tiny as this, just a personal website and my domain host simply does not provide PHP, only for "hard money" which I'm not going to spend.

the code wouldn't be a mess, in fact the code only needs to be a few lines (like in my edited post, except you would have to use $.get first to get your json from the server.

 

The problem is, your site would only  work if javascript is enabled and you wouldn't be able to code a fallback. Search engines wouldn't be able to index your site in the other languages, so you would lose visitors because of that. And people with visual disabilities wouldn't be able to use your site either as their screen readers would probably flip out. All in all, very much possible, very much a bad idea

  • 0
  On 17/07/2013 at 09:17, the better twin said:

You could try Google's Ajax Language API.

Heres a tutorial: 

http://www.labnol.org/internet/website-translation-with-google-language-api/4367/

that just does automatic translation, the results are terrible and it has the same drawbacks

  • 0
  On 17/07/2013 at 09:18, XerXis said:

that just does automatic translation, the results are terrible and it has the same drawbacks

Fair enough. Sounds like you have much more experience with this than I do. 

  • 0

Just use JS in this case, make a duplicate off all elements and give each duplicate it's own class (english, german etc) then make sure they're all hidden by default, based on visitor language you can show .english or .german or .whatever with js.

 

Make sure to add a noscript element informing visitors who don;t have js why they don't see anything.

 

 

Edit: http://www.websitecodetutorials.com/code/javascript/multilingual-website-demo1.php here's some js that can help which includes cookies too so they preference stays saved.

  • 0
  On 17/07/2013 at 09:15, XerXis said:

the code wouldn't be a mess, in fact the code only needs to be a few lines (like in my edited post, except you would have to use $.get first to get your json from the server.

 

The problem is, your site would only  work if javascript is enabled and you wouldn't be able to code a fallback. Search engines wouldn't be able to index your site in the other languages, so you would lose visitors because of that. And people with visual disabilities wouldn't be able to use your site either as their screen readers would probably flip out. All in all, very much possible, very much a bad idea

 

Oh, sry, I didn't see you edited. Will take a look right away...

 

Now I got what you mean. True. I don't want to drag actually any visitors. It's just I use the domain mainly for my private email, I just want to have a tiny website behind it, so if by accident someone is think, {oh, let's open that website} there should be something. I just use it in my CV and stuff, it's much better to have not a @gmail.com ending. Will try to think of something else...

 

  On 17/07/2013 at 09:17, the better twin said:

You could try Google's Ajax Language API.

Heres a tutorial: 

http://www.labnol.org/internet/website-translation-with-google-language-api/4367/

 

EDIT: tutorials a bit outdated 

 

Agree, it's pretty outdated and horrible translates coming up.

 

  On 17/07/2013 at 09:18, XerXis said:

that just does automatic translation, the results are terrible and it has the same drawbacks

 

Yup.

 

  On 17/07/2013 at 09:26, the better twin said:

Fair enough. Sounds like you have much more experience with this than I do. 

 

But thanks for the suggestion, it's always welcome. I'm a huge noob myself is coding and stuff.

 

  On 17/07/2013 at 09:48, Seahorsepip said:

Just use JS in this case, make a duplicate off all elements and give each duplicate it's own class (english, german etc) then make sure they're all hidden by default, based on visitor language you can show .english or .german or .whatever with js.

 

Make sure to add a noscript element informing visitors who don;t have js why they don't see anything.

 

 

Edit: http://www.websitecodetutorials.com/code/javascript/multilingual-website-demo1.php here's some js that can help which includes cookies too so they preference stays saved.

 

Actually, that class stuff in .js seems like a good idea, but as I see that site is a PHP code, isn't it? Well, by "inspecting" it, I didn't see any PHP code...so this might work smooth as oiling hot girl on the beach. :D

 

Just to analyze and understand the code a bit....in the header you define 2 css, each having the their own visual setting inside.

<link href="english.css" rel="stylesheet" type="text/css">
<link href="spanish.css" rel="alternate stylesheet" type="text/css" title="alternate">

Then, inside the english.css you just simply hide/block the unwanted text with this:

.spanish {
display:none;
}

in the other, the spanish.css you set:

.spanish {
display:block;
}
li .spanish {
display:inline;
}
.english {
display:none;
}

Back to the original index.html, you setup a java script that makes the switch dynamically:

<script src="styleswitch.js" type="text/javascript"></script>

Which is this code:

function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
if (document.getElementById){
setStylesheet(styletitle)
setCookie("mysheet", styletitle, days)
}
}

Finally, you make 2 buttons/link that command the .js to execute:

<a href="javascript:chooseStyle('none', 60)">English Language</a>
<a href="javascript:chooseStyle('alternate', 60)">Spanish Language</a>

That about it, right?

 

Oh, and you have to make double entries inside the index.html, like this:

<span class="english">English</span>
<span class="spanish">Spanish</span>
  • 0

Doing it client side is going to be pretty crappy (The client will basically end up downloading every page twice + lay it out twice/etc.). This is something ideally suited to a server side templating/framework library, a good one should support it transparently.

  • 0
  On 17/07/2013 at 10:22, The_Decryptor said:

Doing it client side is going to be pretty crappy (The client will basically end up downloading every page twice + lay it out twice/etc.). This is something ideally suited to a server side templating/framework library, a good one should support it transparently.

 

yes, the workload should be on the server, not on the client; you are only making a worse experience for the user if the heavy load is processed client side.

  • 0
  On 17/07/2013 at 10:22, The_Decryptor said:

Doing it client side is going to be pretty crappy (The client will basically end up downloading every page twice + lay it out twice/etc.). This is something ideally suited to a server side templating/framework library, a good one should support it transparently.

 

True. But if that not possible, there is really only 2 options left.

  1. Leave it only english, that (almost) everyone is speaking
  2. Or make a client side "switch" in language....that css + js doesn't seem to do that much of a load for a website that consist only from a index.html, i think. So, in a big scale might be a crappy solution. For a single index.html, shouldn't be the case or?

 

  On 17/07/2013 at 10:58, Praetor said:

yes, the workload should be on the server, not on the client; you are only making a worse experience for the user if the heavy load is processed client side.

 

I have no other idea for it...

  • 0

i'm not sure you *have* to use javascript. I played with XML and XSLT a long time ago, which is very powerful once you figure out the basics of how it works. You can just make multiple XML files each with a different language which contains all the words on the page (using custom structure/tags, since XML uses arbitrary tags), in each XML reference an XSLT stylesheet, which you can use to render it to html, and in the XSLT make reference to a CSS file to style the HTML that just got derived from your XML file. That way you can just have links to each XML file for the different languages, but still only have one-ish place to edit to change the style.

 

obviously, just as hacky as the aforementioned suggestions, the best is still to do it server-side, so much easier.

  • 0

Server side isn't possible in his case (I wonder how he was able to find hosting which is so bad that they don't support php or asp atleast xD).

@primexx isn't using external xml files for each language it actually making worse? since you're doing additional http request :p

 

 

Easiest would be just a index php with language detect from ip and then load the correct php file with "include", I'd just get a better hosting to be honest :/

  • 0
  On 17/07/2013 at 15:37, Seahorsepip said:

Server side isn't possible in his case (I wonder how he was able to find hosting which is so bad that they don't support php or asp atleast xD).

@primexx isn't using external xml files for each language it actually making worse? since you're doing additional http request :p

 

 

Easiest would be just a index php with language detect from ip and then load the correct php file with "include", I'd just get a better hosting to be honest :/

 

well all these workarounds suck. I agree a better host is best.

  • 0
  On 17/07/2013 at 15:37, Seahorsepip said:

Server side isn't possible in his case (I wonder how he was able to find hosting which is so bad that they don't support php or asp atleast xD).

@primexx isn't using external xml files for each language it actually making worse? since you're doing additional http request :p

 

 

Easiest would be just a index php with language detect from ip and then load the correct php file with "include", I'd just get a better hosting to be honest :/

 

It's really cheap! Do don't consider it as a webhost, more like I pay only for the domain and they provide a flat-easy only HTML webhosting for that. It's costs 20EUR for 3 years, aprox less then 30$. So for this price? Will you get a domain name + proper webhosting? Doubt it...or?!

 

Actually, previously I had website where I made my language change with a simple PHP, without knowing PHP even. Anyway, now I have this host, what can I do? I don't want to spend more on then it's actually worth. HTML5 is nice nowadays and in most chases should be enought. 

 

  On 17/07/2013 at 14:18, primexx said:

i'm not sure you *have* to use javascript. I played with XML and XSLT a long time ago, which is very powerful once you figure out the basics of how it works. You can just make multiple XML files each with a different language which contains all the words on the page (using custom structure/tags, since XML uses arbitrary tags), in each XML reference an XSLT stylesheet, which you can use to render it to html, and in the XSLT make reference to a CSS file to style the HTML that just got derived from your XML file. That way you can just have links to each XML file for the different languages, but still only have one-ish place to edit to change the style.

 

obviously, just as hacky as the aforementioned suggestions, the best is still to do it server-side, so much easier.

 

OK. Might dig in a bit into that...althou I started to structure it with the above suggestions.

 

  On 17/07/2013 at 16:07, primexx said:

well all these workarounds suck. I agree a better host is best.

 

True.

  • 0
  On 18/07/2013 at 13:27, Class said:

...

Actually, previously I had website where I made my language change with a simple PHP, without knowing PHP even. Anyway, now I have this host, what can I do? I don't want to spend more on then it's actually worth. HTML5 is nice nowadays and in most chases should be enought. 

...

Just because you can do something on the client, doesn't mean you should (And building the site template is something that should definitely be done on the server)

Yes, you can do a full multi-lingual site with pure HTML/JS, but you don't want to because it creates a bad experience for the user specifically.

This topic is now closed to further replies.
  • Posts

    • Amazon lays off more staff across Goodreads and Kindle divisions by Hamid Ganji Dozens of Amazon employees working on the retailer's book divisions have been laid off. As reported by Reuters, Amazon confirmed that it's cutting jobs across the Goodreads review site and Kindle units, which impacts fewer than 100 workers. Amazon says the recent layoffs across Goodreads and Kindle divisions are meant to improve efficiency and streamline operations. The giant retailer has constantly reduced staff across various divisions over the past few years. According to CEO Andy Jassy, reducing headcounts helps the company to eliminate bureaucracy. "As part of our ongoing work to make our teams and programs operate more efficiently and to better align with our business roadmap, we've made the difficult decision to eliminate a small number of roles within the Books organization," an Amazon spokesperson said. Layoffs recently impacted employees in Amazon's Wondery podcast division, devices and services units, communications, and in-store staff. However, Amazon's Q1 results show the retailer has added about 4,000 jobs compared to Q4 2024. After the Covid pandemic settled down, many companies began laying off thousands of staff they hired during the pandemic to respond to growing demands. The layoff trend among tech firms still exists today, and AI has amplified it. The latest data shows that in 2025, about 62,832 tech employees were laid off across 141 tech companies. Also, 152,922 tech employees across 551 companies were laid off in 2024. More layoffs are expected to occur due to declining economic growth, tariffs, and the expansion of AI across companies. Amazon is also gearing up to double down in AI investments and robotics. The company has recently announced the forming of a new agentic AI team to develop an agentic AI framework for use in robotics. Also, a new report by The Information indicates that Amazon has begun testing humanoid robots for package delivery.
    • Major Privacy 0.98.1.1 Beta by Razvan Serea MajorPrivacy is a cutting-edge privacy and security tool for Windows, offering unparalleled control over process behavior, file access, and network communication. It is a continuation of the PrivateWin10 project. By leveraging advanced kernel-level protections, MajorPrivacy creates a secure environment where user data and system integrity are fully safeguarded. Unlike traditional tools, MajorPrivacy introduces innovative protection methods that ensure mounted encrypted volumes are only accessible by authorized applications, making it the first and only encryption solution of its kind. MajorPrivacy – Ultimate Privacy & Security for Windows key features Process Protection – Isolate processes to block interference from unauthorized apps, even with admin privileges. Software Restriction – Block unwanted apps and DLLs to ensure only trusted software runs. Revolutionary Encrypted Volumes Secure Storage – Create encrypted disk images for sensitive data. Exclusive Access – Unlike traditional tools, only authorized apps can access mounted volumes—blocking all unauthorized processes. File & Folder Protection – Lock down sensitive files and prevent unauthorized access or modifications. Advanced Network Firewall – Control which apps can send or receive data online. DNS Monitoring & Filtering – Track domain access and block unwanted sites (Pi-hole compatible filtering coming soon). Tweak Engine – Disable telemetry, cloud integration, and invasive Windows features for better privacy. Why MajorPrivacy? Kernel-Level Security – Protects at the deepest system level. Unmatched Encryption Protection – Keeps mounted volumes safe from all unauthorized access. Full System Control – Block, isolate, or restrict processes as needed. Enhanced Privacy – Stops Windows & apps from collecting unnecessary data. Perfect for privacy-conscious users, IT pros, and anyone who wants total system control. Major Privacy 0.98.1.1 Beta changelog: The 0.98.1 release of MajorPrivacy introduces significant enhancements and a number of critical fixes aimed at improving usability, localization, and system integration. A major new feature is the introduction of full translation support, allowing the application interface and tweaks to be localized into multiple languages. Initial translations include AI-assisted German and Polish versions, a community-contributed Turkish translation, and Simplified Chinese. Users interested in contributing translations or adding new languages are encouraged to participate via the forum. This version also improves compatibility and deployment by bundling the Microsoft Visual C++ Redistributable with the installer, which is required for the ImDisk user interface. Several important bugs have been resolved. The installer now correctly removes the driver during uninstallation. Tweak definitions have been cleaned up for better consistency. A number of networking issues were addressed, including failures related to network shares and incorrect handling of mapped drive letters. It is now required to use full UNC paths for defining rules involving shared resources. Additionally, configuration persistence issues on system shutdown have been fixed, as well as problems affecting protected folder visibility and rule precedence involving enclave conditions. Finally, the underlying driver code has been refactored, laying the groundwork for better maintainability and future enhancements. MajorPrivacy-v0.98.1.1.exe (0.98.1a) hotfix for #71 Download: Major Privacy 0.98.1.1 Beta | 47.4 MB (Open Source) View: MajorPrivacy Home Page | Github Project page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • OpenAI responds to The New York Times' ChatGPT data demands by Pradeep Viswanathan The New York Times has sued OpenAI for the unauthorized use of its news articles to train large language models. As part of the ongoing lawsuit, the NYT recently asked the court to require OpenAI to retain all ChatGPT user content indefinitely. The NYT's argument is that they may find something in the data that supports their case. Brad Lightcap, COO of OpenAI, wrote the following regarding the NYT's sweeping demand: OpenAI has already filed a motion asking the Magistrate Judge to reconsider the preservation order, since indefinite retention of user data breaches industry norms and its own policies. Additionally, OpenAI has also appealed this order with the District Court Judge. Until OpenAI wins its appeal, it will be complying with the court order. The content defined by the court order will be stored separately in a secure system and will be accessed or used only for meeting legal obligations. Only a small, audited OpenAI legal and security team will be able to access this data as necessary to comply with our legal obligations. As of early 2025, ChatGPT has over 400 million weekly active users, and this data retention order will affect a significant number of them. OpenAI confirmed that ChatGPT Free, Plus, Pro, and Teams subscription users, and developers who use the OpenAI API (without a Zero Data Retention agreement) will be affected by this order. ChatGPT Enterprise, ChatGPT Edu, and API customers who are using Zero Data Retention endpoints will not be affected by this court change.
  • Recent Achievements

    • First Post
      Uranus_enjoyer earned a badge
      First Post
    • Week One Done
      Uranus_enjoyer earned a badge
      Week One Done
    • Week One Done
      jfam earned a badge
      Week One Done
    • First Post
      survivor303 earned a badge
      First Post
    • Week One Done
      CHUNWEI earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      428
    2. 2
      +FloatingFatMan
      238
    3. 3
      ATLien_0
      212
    4. 4
      snowy owl
      211
    5. 5
      Xenon
      159
  • Tell a friend

    Love Neowin? Tell a friend!