GithubHelp home page GithubHelp logo

neetjn / r-localize Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 571 KB

Localization plugin for Riot.js based off of Vue.js v-localize project.

Home Page: https://neetjn.github.io/r-localize/

License: MIT License

TypeScript 59.61% JavaScript 40.39%
riot i18n localize locale i10n javascript node webpack google typescript ts

r-localize's Introduction

r-localize

build npm version npm

NPM

About

r-localize is a localization plugin for Riot.js based off of Vue.js v-localize project.

Support

Chome Edge Firefox Opera Safari
5.0+ ✔ 4.0+ ✔ 11.50+ ✔ 5.0+ ✔

This project was developed using Riot.js 3, support for previous versions is not available.

Usage

To install via NPM, simply do the following:

npm install r-localize

For a quick start using jsdelivr:

<script src="https://cdn.jsdelivr.net/npm/r-localize/dist/r-localize.js"></script>

Using the plugin is then as simple as:

import riot from 'riot'
import Localize from 'r-localize'

const options = {
  debug: true,
  default: 'en-US',
  fallback: '-',  
  available: ['en-US', 'es-SP']
}

const localizations = {
  'en-US': {
    'header': 'international',
    'menu': {
      'help': 'Help'
    }
  },
  'es-SP': {
    'header': 'internacional',
    'menu': {
      'help': 'Ayuda'
    }
  }
}

localize = new Localize(riot, options, localizations)

Once your Riot app has been mounted, the language can be changed by calling localize.locale(args*) from your component.

<component>
  <select change={ locale }>
    <option value="en-US">English</option>
    <option value="es-SP">Spanish</option>
  </select>
  <script>
    locale(e) {
      this.localize.locale(e.target.value)
    }
  </script>
</component>

You can specify your localizations like so:

<!-- add a localized title to this element targeting en-US -->
<h1 data-is="localize" t={{ i: 'header', attr: 'title' }} />
<!-- replace this element's text with localized item -->
<h1 data-is="localize" t="menu.help">

Alternatively, you can fetch your current localization by calling locale without any arguments.

<h1>Current Locale: { localize.locale() }</h1>

For fetching a specific locale item programatically within a component method:

<h1>Translated Item: { localize.translate('header', 'es-SP') }</h1>

Configuration

The plugin takes 5 options,

*available: List of available localizations.

['en-US', 'es-SP', 'pr-BR', {
  locale: 'ar-MS',
  orientation: 'rtl'
}]

*debug: Spit info, warnings and errors to console.

*default: Default locale key to target.

fallbackContent: Use the existing node's text content if enabled and requested localization is not found.

*fallback: Default text to show if localization for current language not found.

webStore: If the mixin is accessed within a web context and option webStore is enabled, mixin will store the locale in local storage for the next visit.

Locale Options

Locale configuration currently supports the following options,

orientation: Text direction of target element, useful for orientation of script languages.

fontFamily: Font family to change to. Re: https://www.w3schools.com/jsref/prop_style_fontfamily.asp

Contributors

Contributing guidelines can be found here.


Copyright (c) 2018 John Nolette Licensed under the MIT license.

r-localize's People

Contributors

neetjn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

r-localize's Issues

Replace Karma/Electron setup with Jest + Jest-Dom for testing

  1. Describe your issue:

Karma / Electron setup for testing should be replaced with Jest + Jest-Dom. It's advantageous in size, flexibility, and less security vulnerabilities to update.

  1. Can you reproduce the issue?

  2. On which browser/OS does the issue appear?

  3. Which version of r-localize does it affect?

  4. How would you tag this issue?

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance

Add capability/setting to fallback to original element text.

IMPORTANT

Your issue might be labeled as invalid and eventually closed if:

  • You have deleted completely the issue template for no reason
  • You can not reproduce the issue
  • Your question is not an issue nor a feature request but it's only a support/consulting request (use stack overflow for it)
  • Your post violates our code of conduct

Help us to manage our issues by answering the following:

  1. Describe your issue:

r-localize should have a setting to allow falling back to the original DOM node's text content.

  1. Can you reproduce the issue?

  2. On which browser/OS does the issue appear?

  3. Which version of r-localize does it affect?

  4. How would you tag this issue?

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance

Add support for Riot.js 4

Help us to manage our issues by answering the following:

  1. Describe your issue:

This project should have support for Riot.js 4.

  1. Can you reproduce the issue?

  2. On which browser/OS does the issue appear?

  3. Which version of r-localize does it affect?

  4. How would you tag this issue?

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance

Initial Spec v 0.0.1

I'd like to create a v-localize port for Riot.js.

Logic: Split the project into a mixin and a tag. The mixin will take care of actually storing and retrieving the locales/localizations. The tag be a partial tag and reference the mixin for localizing text content and attributes.

Features:

  • Observable w/ lifecycle events.
  • Optional translation query for Google.
  • Attribute localization.
  • Ability to fetch localized items via the mixin w/o the tag.

An internationalization tag/mixin already exists for Riot (riot-i18n) but it doesn't have all the features I'm looking for and won't work with webpack because of the way it was built.

r-localize will be built for Riot 3 exclusively, and will not offer support for previous versions.

Update vulnerable packages

IMPORTANT

Your issue might be labeled as invalid and eventually closed if:

  • You have deleted completely the issue template for no reason
  • You can not reproduce the issue
  • Your question is not an issue nor a feature request but it's only a support/consulting request (use stack overflow for it)
  • Your post violates our code of conduct

Help us to manage our issues by answering the following:

  1. Describe your issue:

There are vulnerable packages being used by r-localize for building and testing.

  1. Can you reproduce the issue?

  2. On which browser/OS does the issue appear?

  3. Which version of r-localize does it affect?

  4. How would you tag this issue?

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance

Implement locale options

IMPORTANT

Your issue might be labeled as invalid and eventually closed if:

  • You have deleted completely the issue template for no reason
  • You can not reproduce the issue
  • Your question is not an issue nor a feature request but it's only a support/consulting request (use stack overflow for it)
  • Your post violates our code of conduct

Help us to manage our issues by answering the following:

  1. Describe your issue:

I would like to implement locale options into r-localize, similar to the functionality provided by v-localize.
Related Issue: neetjn/v-localize#5

  1. Can you reproduce the issue?

  2. On which browser/OS does the issue appear?

  3. Which version of r-localize does it affect?

  4. How would you tag this issue?

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance

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.