Giter VIP home page Giter VIP logo

locize-editor's Introduction

Travis npm version Bower David

locize-editor

The locize-editor enables you to directly connect content from your website / application with your content on your localization project on locize.

Enabling the editor by querystring ?locize=true you can click any text content on your website to open it on the right side editor window:

The linking could be turned on/off using the button on the lower right or by pressing ctrl-x.

Getting started

Source can be loaded via npm, bower, downloaded from this repo or loaded from the npm CDN unpkg.com/locize-editor.

If not using a bundler the script will be added to window.locizeEditor.

locizify

The editor is built into our locizify script. There is no additional step needed.

Open edit mode by appending ?locize=true to the querystring.

For texts using plural or interpolation feature you might need to additionally add &lng=cimode&useLng=[yourLocal] to find a key.

i18next with i18next-locize-backend

import locizeEditor from 'locize-editor';
import i18next from 'locize';
import Backend from 'i18next-locize-backend';

i18next
  .use(Backend)
  .use(locizeEditor);

find the namespace

As content is structured into multiple translation files we somehow need to detect/find the namespace (file) used for translating the clicked content.

by adding attribute containing namespace

The namespace will be detected from current clicked element or any of its parents.

Following attributes are valid to look it up:

<!-- preferred -->
<div i18next-ns="myNamespace">content</div>
<div data-i18next-ns="myNamespace">content</div>

<!-- alternative: json stringified i18next options-->
<div i18next-options="{\"ns\":\"myNamespace\"}">content</div>
<div data-i18next-options="{\"ns\":\"myNamespace\"}">content</div>
by using cimode language

If there is no possibility to find the used namespace per attribute on parent element you will need to toggle the lng to cimode. Additionally you will need to configure locize to append namespace in cimode by:

i18next.init({
  appendNamespaceToCIMode: true
});

open your website with querystring ?locize=true&lng=cimode&useLng=[yourLocal].

Initialize with optional options

You can configure some aspects like layout by adding init options.

locizify|locize|i18next.init({
  editor: {
    // enable on init without the need of adding querystring locize=true
    enabled: false,
    autoOpen: true, // if set to false you will need to open it via API

    // enable by adding querystring locize=true; can be set to another value or turned off by setting to false
    enableByQS: 'locize',

    // turn on/off by pressing
    toggleKeyModifier: 'ctrlKey', // metaKey | altKey | shiftKey
    toggleKeyCode: 24, // x when pressing ctrl (e.which: document.addEventListener('keypress', (e) => console.warn(e.which, e));

    // use lng in editor, eg. if running with lng=cimode (i18next, locize)
    lngOverrideQS: 'useLng',

    // default will open a iframe; setting to window will open a new window/tab instead
    mode: 'iframe' // 'window',

    // styles to adapt layout in iframe mode to your website layout
    iframeContainerStyle: 'z-index: 1000; position: fixed; top: 0; right: 0; bottom: 0; width: 500px; box-shadow: -3px 0 5px 0 rgba(0,0,0,0.5);',
    iframeStyle: 'height: 100%; width: 500px; border: none;',
    bodyStyle: 'margin-right: 505px;'
  }
});

locize-editor's People

Contributors

jamuhl avatar

Watchers

Maciej Warszawski avatar James Cloos 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.