GithubHelp home page GithubHelp logo

pdx-i18n's Introduction

pdx-i18n

what is this?

If you need a translation tool in your H5 project, try this

demo

Please link demo

feature

Support translate

  1. html
  2. placeholder
  3. variable

how to use?

  • install pxd-i18n package
npm i pdx-i18n
  • before use this ,add translate js file.
|-src
 |-i18n
   |-en
     |-module.js
   |-zh-cn
     |-module.js
   |-zh-hant
     |-module.js
   |-...

Please make sure the sub file name of en/zh-ch/... are same

  • import the module into main.js
import pdxI18n from 'pdx-i18n';
window.onload = function () {
  // Instantiation internationalization
  const myI18n = initI18N('zh-hant', 'add');

  // Simplified Chinese
  document.querySelector('#cn').addEventListener('click', ()=>{
    myI18n.setInnerHtml('zh-cn');
  });

  // traditional Chinese
  document.querySelector('#hant').addEventListener('click', ()=>{
    myI18n.setInnerHtml('zh-hant');
  });

  // english
  document.querySelector('#en').addEventListener('click', ()=>{
    myI18n.setInnerHtml('en');
  })
};

// Initialization internationalization
function initI18N(currentlang, currentFile) {
  const i18n =  new pdxI18n({
    currentLang: currentlang,
    useFileName: currentFile
  });
  i18n.setInnerHtml();
  return i18n;
}

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
</head>
<body>
<section>
  <div class="icon-bg"></div>
  <div id="create" class="lx-button lx-button-black i18n" data-i18n="btnCreate"><!--Create wallet--></div>
  <div id="import" class="lx-button i18n" data-i18n="btnImport"><!--Import wallet--></div>
  <button id="cn">zh-cn</button>
  <button id="hant">zh-hant</button>
  <button id="en">english</button>
  <br>
</section>
  <script src="./main.js"></script>
</body>
</html>

Please make sure project i18n file structure fit for under url ${window.location.href}i18n/${this.currentLang}/${this.useFileName}.js For example: http://xxx.xxx.xx:port/i18n/en/xxxx.js

api

new pdxI18n({currentLang: string,useFileName: string})

currentLang: the name of you create to put deffirent language file name . for example: en/zh-cn/zh-hant

useFileName: the name of module.js . for example: /en/module.js the useFileName is 'module'

   const i18n =  new pdxI18n({
      currentLang: currentlang,
      useFileName: currentFile
    });

setInnerHtml(lang: string)

translate html tag innerText value lang: currentLang

i18n.setInnerHtml('en');
or
i18n.setInnerHtml();

setPlaceholderLang(lang: string)

translate the placeholder of the element

  i18n.setPlaceholderLang('en');
  or
  i18n.setPlaceholderLang();

setObjsLang(variableName: string, lang: string, callback)

translate variable lang: needn't pass

const i18nObj = {};
i18n.setObjsLang('i18nObj', currentlang, data => {
    console.log(data);
});
or
myI18n.setObjsLang('i18nObj', 'en', data => {
   console.log(data);
});

the complete guide check the dome,please.

pdx-i18n's People

Contributors

tinalst avatar

Watchers

 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.