Dowload
or
or
or
bower install xktta --save-dev
or
npm install xktta --save-dev
What's it?
Implementing Internationalization and Validation with Javascript. Based on the ebook Eloquent Javascript 2nd edition and Rails
Xktta init //I18n: create as you like //Validator: create as you like //Class: create as you like ; var className = ;var otherClassName = ;I18n;I18n;'singularWord'pluralize;isEmpty;{}toJson;'{}'asJson;'#{first} #{last}';
Use cases
Customer
Design
Custormer: id: attribute name: attribute, required lastName: attribute, required document: attribute, required street: attribute, minimum 8 characters, maximum 16 characters district: attribute, minimum 8 characters, maximum 16 characters phone: attribute, minimum 9 digits user: hasOne association, persisted fullName: object method, '#{name} #{lastName}' className: class method, class name
Implementation
Xktta ;
How to
var customer = ;
User
Design
User: id: attribute email: attribute, required custormer_id: attribute persona_id: attribute, required customer: belongsTo association persona: belongsTo association
Implementation
Xktta ;
How to
var user = ;
Persona
Design
Persona: id: attribute name: attribute, required users: hasMany association
Implementation
Xktta ;
How to
var persona = ;
It works for you too?
Prepare
Xktta init
Setting up internal communication of lib
You must set the number of flection of the names of their classes to the lib be able to relate members and collections.
You can verifying calling the following methods on String objects:
'person'pluralize;'people'singularize;
Nationalizing the output to client
You must set the output data for each language supported by your application.
I18n methods:
- locale= set locale
- locale return actual locale
- translate('path.sub_path',{}) return string by path
- t(object ,{}) alias to translate method
- localize(object ,{}) convert object to string
- l(object ,{}) alias to localize method
Nationalizing
You must choose one of the languages supported by your application.
I18nlocale = 'en';
Nationalizing date
You must set expressions to convert data to string using an external library or the following options.
Date Options:
- %a convert to abbreviation day name
- %A convert to day name
- %b convert to abbreviation month name
- %B convert to month name
- %d convert to day number
- %m convert to month number
- %Y convert to year number
date: formats: default: '%Y-%m-%d' long: '%B %d, %Y' short: '%b %d' { return 'use external lib to format date'; }
Now you can use the convert date objects to string according to the set language.
var date = ; I18n;I18n;I18n;I18n; date;date;
Nationalizing time
You must set expressions to convert time to string using an external library or the following options.
Date Options:
- %h convert to hour (12h)
- %H convert to hour (24h)
- %M convert to minute
- %S convert to second
- %p convert to meridiem (am/pm)
- %z convert to zone
time: am: 'am' formats: default: '%H:%M:%S %z' long: '%H:%M' meridiem: '%h:%M:%S %p %z' meridiemLong: '%h:%M %p' { return 'use external lib to format time'; } pm: 'pm'
Now you can use the convert time objects to string according to the set language.
var time = ; I18n;I18n;I18n;I18n; time;time;
Nationalizing datetime
You must set expressions to convert datetime to string using an external library or the following options.
Date Options:
- %a convert to abbreviation day name
- %A convert to day name
- %b convert to abbreviation month name
- %B convert to month name
- %d convert to day number
- %m convert to month number
- %Y convert to year number
- %h convert to hour (12h)
- %H convert to hour (24h)
- %M convert to minute
- %S convert to second
- %p convert to meridiem (am/pm)
- %z convert to zone
datetime: am: 'am' formats: default: '%a, %d %b %Y %H:%M:%S %z' long: '%B %d, %Y %H:%M' short: '%d %b %H:%M' { return 'use external lib to format datetime'; } pm: 'pm'
Now you can use the convert datetime objects to string according to the set language.
var datetime = ; I18n;I18n;I18n;I18n; datetime;datetime;
Nationalizing integer
You must set expressions to convert integer to string using an external library.
integer: formats: { return 'use external lib to format integer'; } { return 'use external lib to other format integer'; }
Now you can use the convert integer objects to string according to the set language.
var integer = 9; I18n;I18n; integer;integer;
Nationalizing decimal
You must set expressions to convert decimal to string using an external library.
decimal: formats: { return 'use external lib to format decimal'; } { return 'use external lib to other format decimal'; }
Now you can use the convert decimal objects to string according to the set language.
var decimal = 999; I18n;I18n; decimal;decimal;
Nationalizing logic
You must set expressions to convert logic to string using an external library.
logic: formats: default: true: 'No' false: 'Yes' other: true: 'NOT' false: 'OK'
Now you can use the convert logic objects to string according to the set language.
var logic = true; I18n;I18n; logic;logic;
Nationalizing message
You must set expressions to convert message to string.
messages: one: 'Message One' two: 'Message Two' other: 'Message Other to %{name}'
Now you can use the convert message objects to string according to the set language.
I18n;I18n; I18n;I18n;
Building classes
You must build your classes using this function.
Now you can build and use your objects.
var stub2 = ;stub2ident;stub2ident = 10; var stub = ;stubid;stubid = 10;stubone;stubone = 11;stubtwo;stubone = 3; stubisValid;stuberrors;stuberrorsmessages;stuberrorsfull_messages; var stub = two: 3;stubchanges;stubchanges_id;stubchanges_one;stubchanges_two; stubchanged;stubchanged_id;stubchanged_one;stubchanged_two; stubreset; stub;StubclassName; stubtoJson;stubasJson;