Giter Club home page Giter Club logo

meteor-simple-schema-i18n's Introduction

Overview

Support Node SimpleSchema validation messages i18n using TAPi18n package. Reactively depends on TAPi18n.getLanguage() on the Client.

Installation

meteor add imajus:simple-schema-i18n

And, if tap:i18n is not in the project yet:

meteor add tap:i18n

Features

  1. Fetch SimpleSchema MessageBox messages translation for each langauge from TAPi18n.getLanguages() on Meteor.startup().
  2. (Client only) All SimpleSchemai18n instances depend reactively on TAPi18n.getLanguage().
  3. Extend schema options with { tracker: Tracker } so you don't need to provide this option to every SimpleSchema constructor call anymore.
  4. Initially extend SimpleSchema with ['autoform', 'denyInsert', 'denyUpdate'] options.
  5. Set SimpleSchema.debug to Meteor.isDevelopment.

Usage

i18n/en.i18n.json

{
  "simple-schema-i18n": {
    "required": "{{{label}}} is required"
  }
}

Example, you actually need to fill the "simple-schema-i18n" section with all messages.

i18n/ru.i18n.json

{
  "simple-schema-i18n": {
    "required": "{{{label}}} обязательное поле"
  }
}

Example, you actually need to fill the "simple-schema-i18n" section with all messages.

project-tap.i18n

{
    "helper_name": "_",
    "supported_languages": null,
    "i18n_files_route": "/i18n",
    "cdn_path": null,
    "preloaded_langs": ["*"]
}

Here, "preloaded_langs" option is crucial for package to work properly. Other options could be changed as you like.

import { SimpleSchema } from 'meteor/imajus:simple-schema-i18n';

const schema = new SimpleSchema({ /* Fields definition */ });

const message = { type: 'required', label: 'Field' };
console.log(schema.messageBox.message(message, { language: 'en' }));
// Output: Field is required
console.log(schema.messageBox.message(message, { language: 'ru' })); 
// Output: Field обязательное поле

/**
 * Уou can use this SimpleSchema as usual, the language of validation errors
 * will reactively depend on TAPi18n.getLanguage() and change accordingly.
 */

Converting existing code

Let's assume your current code look like this:

import { Tracker } from 'meteor/tracker';
import SimpleSchema from 'simpl-schema';

const schema = new SimpleSchema({ /*…*/ }, { tracker: Tracker });

To support SimpleSchema i18n, the code above must be change to this:

import { SimpleSchema } from 'meteor/imajus:simple-schema-i18n';

const schema = new SimpleSchema({ /*…*/ })

Obviously, you also need to add tap:i18n Meteor package dependency and create actual i18n files.

Known issues

For some reason I couldn't embed initial translations in package itself. TAPi18n currently doesn't work well on package level, and as far as I can see package author is not willing to fix any bugs in the nearest future. That's why I've switched to project level i18n files instead.

meteor-simple-schema-i18n's People

Contributors

imajus 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.