Comments (8)
I have made few changes in jquery-i18next.js starting line no: 67 in my local to fix this:
Old Code:
else if (attr === 'prepend') { ele.prepend(i18next.t(key, extendDefault(opts, ele.html()))); }
New Code:
else if (attr === 'prepend') { if (ele.find("#" + key).length > 0) { ele.find("#" + key).html(i18next.t(key, extendDefault(opts, ele.html()))); } else { ele.prepend("<span id=" + key.split(" ").join("") + ">" + i18next.t(key, extendDefault(opts, ele.html())) + "</span>"); } }
Can you please suggest if this is a valid fix or do you have any other proper fix or suggestions?
Thanks,
Bhasker
from jquery-i18next.
seems valid. If you like you can provide a PR changing both prepend and append.
from jquery-i18next.
Hi @jamuhl ,
Sorry I cannot raise a PR as I don't have access to git installed on my pc at office due to securoty reasons and even I cannot clone git repo due to network proxy.
May be you can please go ahead and make the necessary changes as suggested for prepend and append attributes. Hope it is fine.
Thanks,
Bhasker
from jquery-i18next.
published [email protected]
from jquery-i18next.
cool thanks 👍
from jquery-i18next.
Hi @jamuhl,
There seems to be a small glitch in the fix as I am not trimming the spaces in the key when I am actually trying to find the element but I did so when I am actually assigning the id which could cause the problem.
PF link of screenshot for the changes required for the same and I am also adding the code changes below for the full function parse starting line no: 43.
function parse(ele, key, opts) {
if (key.length === 0) return;
var attr = 'text';
// Removing any spaces in key for valid id
var trimmedKey = key.split(' ').join('');
if (key.indexOf('[') === 0) {
var parts = key.split(']');
key = parts[1];
attr = parts[0].substr(1, parts[0].length - 1);
}
if (key.indexOf(';') === key.length - 1) {
key = key.substr(0, key.length - 2);
}
function extendDefault(o, val) {
if (!options.parseDefaultValueFromContent) return o;
return babelHelpers.extends({}, o, { defaultValue: val });
}
if (attr === 'html') {
ele.html(i18next.t(key, extendDefault(opts, ele.html())));
} else if (attr === 'text') {
ele.text(i18next.t(key, extendDefault(opts, ele.text())));
} else if (attr === 'prepend') {
if (ele.find('#' + trimmedKey).length > 0) {
ele.find('#' + trimmedKey).html(i18next.t(key, extendDefault(opts, ele.html())));
} else {
ele.prepend('<span id=' + trimmedKey + '>' + i18next.t(key, extendDefault(opts, ele.html())) + '</span>');
}
} else if (attr === 'append') {
if (ele.find('#' + trimmedKey).length > 0) {
ele.find('#' + trimmedKey).html(i18next.t(key, extendDefault(opts, ele.html())));
} else {
ele.append('<span id=' + trimmedKey + '>' + i18next.t(key, extendDefault(opts, ele.html())) + '</span>');
}
} else if (attr.indexOf('data-') === 0) {
var dataAttr = attr.substr('data-'.length);
var translated = i18next.t(key, extendDefault(opts, ele.data(dataAttr)));
// we change into the data cache
ele.data(dataAttr, translated);
// we change into the dom
ele.attr(attr, translated);
} else {
ele.attr(attr, i18next.t(key, extendDefault(opts, ele.attr(attr))));
}
}
May be you can move this fix once you publish the next version.
Thanks,
Bhasker
from jquery-i18next.
published [email protected]
from jquery-i18next.
Hi @jamuhl ,
The fix for that issue was to use the below lines of code:
Actually I found the issue the day after I posted the fix for this issue but was busy to post the fix here.
Please update the lines of code in jquery-i18next.js with below 2 lines of code(line no's : 47 and 48):
// Removing any spaces and any invalid special characters in key for valid html5 id
var trimmedKey = key.replace(/[^a-z0-9-_:.]|^[^a-z]+/gi, "");
Thanks,
Bhasker
from jquery-i18next.
Related Issues (20)
- i18next.amd.withJQuery missing in 18next 3.x.x HOT 1
- Load i18next on framework7 ajax loaded pages HOT 8
- Unable to use JQuery 3.1.1 together with jQuery-18next. HOT 2
- jqueryI18next.init is not a function(…) HOT 4
- parser for parseDefaultValueFromContent HOT 4
- Uncaught TypeError: Cannot set property 't' of undefined HOT 8
- Upgrading from i18next.amd.withJQuery - TypeError in init HOT 4
- I can't load json files HOT 1
- How can Key Fallback option be used for translations HOT 3
- localize not defined when .use(i18nextBrowserLanguageDetector) is called HOT 5
- Spaces in data-i18n value for multiple parameters HOT 2
- When there is no default value when binding to an attribute it inserts the key instead of blank HOT 4
- i18next with razor engine HOT 13
- data-i18n not taken into consideration? HOT 2
- Not working for nested boostrap navs HOT 3
- complex replacement i18n vs i18next HOT 2
- How can I use HTML tags? HOT 2
- i18nextHttpBackend looking 'locales' folder under main directory of the server rather than working directory HOT 4
- Replace HTML tags tokens from translation HOT 9
- $.t is not a function with slow networks HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-i18next.