Code Monkey home page Code Monkey logo

langjs's Introduction

Lang.js

Lang.js is a Javascript library that manages multiple languages on a single website. The aim is to show how simple it is to deal with multiple languages on a single website.

There might be plenty different solutions. I choosed to deal with a JavaScript object that links tags' ids to their textual contents.

You might imagine a different solution using an external content file, one for each language or not. Or you can use an external API to translate on the fly the original content.

  • Easy: One Javascript object that contains text in all languages.
  • Flexible: Use as many languages as needed.
  • Clear: No weird behavior neither fancy usage.

Examples

content = {"title": {"en": "Lang Library","fr": "Librairie Lang"},
	   "subtitle": {"en": "Easy, flexible and clear Javascript library to manage languages on a website",
	                "fr": "Une librairie Javascript simple, souple, et claire pour gérer les langages d'un site web"}}
lang = Lang(content)
document.getDocumentById("button_en").addEventListener("click", 
   function(event){
      lang.switchTo("en")
   }
}
document.getDocumentById("button_fr").addEventListener("click", 
   function(event){
      lang.switchTo("fr")
   }
}

This example changes the language of a web site when two buttons are clicked.

Installation

Include the library in your HTML:

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

License

Lang.js is made under the terms of the MIT license.

langjs's People

Contributors

afisse avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.