@ribajs/i18n
Advanced tools
Comparing version 1.4.0 to 1.5.0
{ | ||
"name": "@ribajs/i18n", | ||
"description": "Internationalization module for Riba.js", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"author": "Pascal Garber <pascal@artandcode.studio>", | ||
@@ -45,3 +45,3 @@ "url": "https://github.com/ribajs/riba/tree/master/packages/i18n", | ||
"@babel/runtime-corejs2": "^7.6.3", | ||
"@ribajs/core": "^1.4.0" | ||
"@ribajs/core": "^1.5.0" | ||
}, | ||
@@ -54,2 +54,2 @@ "bugs": { | ||
} | ||
} | ||
} |
@@ -14,3 +14,3 @@ # Internationalization Module | ||
```ts | ||
import { Riba, JQuery } from '@ribajs/core'; | ||
import { Riba, Utils } from '@ribajs/core'; | ||
import { LocalesService } from '@ribajs/shopify-tda'; | ||
@@ -22,5 +22,5 @@ import i18nModule from '@ribajs/i18n'; | ||
riba.module.regist(i18nModule(localesService)); | ||
JQuery(($: JQueryStatic) => { | ||
Utils.domIsReady(() => { | ||
riba.bind(document.body, model); | ||
}); | ||
``` |
@@ -1,2 +0,2 @@ | ||
import { Utils, IBinder, BinderWrapper, JQuery as $ } from '@ribajs/core'; | ||
import { Utils, IBinder, BinderWrapper } from '@ribajs/core'; | ||
import { ALocalesService } from '../../services/locales-base.service'; | ||
@@ -25,6 +25,5 @@ | ||
const customData: any = {}; | ||
customData.$el = $(el); | ||
customData.type = customData.$el.prop('type'); | ||
customData.tagName = customData.$el.prop('tagName'); | ||
customData.contenteditable = customData.$el.attr('contenteditable') ? true : false; | ||
customData.type = (el as HTMLInputElement).type; | ||
customData.tagName = el.tagName; | ||
customData.contenteditable = el.getAttribute('contenteditable') ? true : false; | ||
customData.isRadio = customData.tagName === 'INPUT' && customData.type === 'radio'; | ||
@@ -49,6 +48,6 @@ return customData; | ||
if (this.customData.attributeName === 'html') { | ||
this.customData.$el.html(locale); | ||
el.innerHTML = locale; | ||
} | ||
if (this.customData.attributeName === 'text') { | ||
this.customData.$el.text(locale); | ||
el.innerText = locale; | ||
} | ||
@@ -63,3 +62,3 @@ if (this.customData.attributeName === 'value') { | ||
} | ||
this.customData.$el.attr(this.customData.attributeName, locale); | ||
el.setAttribute(this.customData.attributeName, locale); | ||
}; | ||
@@ -69,3 +68,3 @@ | ||
// parse templates to vars | ||
const newVars = this.customData.i18n.parseTemplateVars(this.customData.$el); | ||
const newVars = this.customData.i18n.parseTemplateVars(_el); | ||
this.customData.vars = Utils.concat(true, this.customData.vars, newVars); | ||
@@ -79,3 +78,2 @@ if (Object.keys(this.customData.vars).length) { | ||
this.customData.vars = Utils.concat(true, this.customData.vars, _el.dataset); | ||
this.customData.vars = Utils.concat(true, this.customData.vars, this.customData.$el.data()); | ||
if (Object.keys(this.customData.vars).length) { | ||
@@ -86,3 +84,3 @@ this.customData.i18n.debug('parsed attribute vars', this.customData.vars); | ||
// Parse templates wich have his own translations | ||
this.customData.langVars = this.customData.i18n.parseLocalVars(this.customData.$el); | ||
this.customData.langVars = this.customData.i18n.parseLocalVars(_el); | ||
if (this.customData.langVars && Object.keys(this.customData.langVars).length) { | ||
@@ -170,3 +168,3 @@ this.customData.i18n.debug('parsed own translations', this.customData.langVars); | ||
// Translate if binder attribute event is changed | ||
this.customData.$el.on('binder-changed', this.customData.onAttributeChanged); | ||
el.addEventListener('binder-changed', this.customData.onAttributeChanged); | ||
}; | ||
@@ -202,3 +200,3 @@ }, | ||
unbind() { | ||
this.customData.$el.off('binder-changed', this.customData.onAttributeChanged); | ||
this.el.removeEventListener('binder-changed', this.customData.onAttributeChanged); | ||
this.customData.i18n.event.off('changed', this.customData.onLanguageChanged); | ||
@@ -205,0 +203,0 @@ }, |
@@ -151,6 +151,6 @@ import { Utils, EventDispatcher, Debug } from '@ribajs/core'; | ||
*/ | ||
public parseTemplateVars($el: JQuery<HTMLElement>): ILocalVar { | ||
const templates = $el.find('template'); | ||
public parseTemplateVars(el: HTMLElement): ILocalVar { | ||
const templates = el.querySelectorAll<HTMLTemplateElement>('template'); | ||
const vars: ILocalVar = {}; | ||
templates.each((i, template) => { | ||
templates.forEach((template) => { | ||
const name: string | null = template.getAttribute('name'); | ||
@@ -167,6 +167,6 @@ if (name !== null) { | ||
*/ | ||
public parseLocalVars($el: JQuery<HTMLElement>): ILocalVar { | ||
const templates = $el.find('template'); | ||
public parseLocalVars(el: HTMLElement): ILocalVar { | ||
const templates = el.querySelectorAll<HTMLTemplateElement>('template'); | ||
const vars: ILocalVar = {}; | ||
templates.each((i, template) => { | ||
templates.forEach((template) => { | ||
const lang: string | null = template.getAttribute('lang'); | ||
@@ -173,0 +173,0 @@ if (lang !== null) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30689
828
Updated@ribajs/core@^1.5.0