Comments (4)
Ok so I boiled it down to as small a tag as I could (guess there's something up
with the parsing), but it seems
this will affect many <pre> tags on my site which contain such example XML code.
Oh well, it was worth a try. I guess this need is pretty non-standard... I
wonder if it would be possible just to
translate, say, the h* and p tags and leave the rest alone? Or conversely,
translate the body and exclude the pre
and code tags? I guess I could just iterate over the DOM...
Original comment by [email protected]
on 31 Jan 2009 at 8:28
from jquery-translate.
This worked better for me:
<script type="text/javascript" src="/static/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript"
src="/static/js/jquery.translate-1.2.6.min.js"></script>
<script type="text/javascript">
google.load("language", "1");
$(document).ready(function(){
/* $('#content').translate('en', 'ja'); */
$('p').translate('en', 'es');
$('li').translate('en', 'es');
});
</script>
Original comment by [email protected]
on 31 Jan 2009 at 8:40
from jquery-translate.
Excluding tags is basically very easy: `$('#content').translate('en', 'ja',
{not:'pre'});`
But if there's some text around it then it won't help:
{{{
<p>
Here's an example:
<pre><link></pre>
</p>
}}}
because in this case the whole paragraph is translated to preserve the context.
And this why the new
translation is set with `.html()`, which causes `"<link>"` to become a
DOMElement. Also, the
`elem is undefined` error is triggered when the plugin tries to re-bind event
handlers attached to
nodes inside the paragraph but the new `link` element exists only in the
translation, not in the
source, so it will be undefined.
The solution is not quite trivial: I could make it "remember" when to use
`.text()` and when
`.html()` but that won't help in my example above as I have no choice but
setting the new content
with `.html()` because there are other real tags in it.
But if you want the content to be translated inside the `pre` tags you can put
it in a textarea
instead, because the plugin uses `.val()` for that, which handles this case
nicely. Or just translate
it separately:
{{{
$('#content').translate('en', 'ja', {not:'pre'});
$.translate( $("pre#id").html(), 'en', 'ja', {
complete:function(){
$("pre#id")[0].innerHTML = this.translation;
}
})
}}}
Hope that helps!
Original comment by balazs.endresz
on 31 Jan 2009 at 12:05
from jquery-translate.
Original comment by balazs.endresz
on 10 Feb 2009 at 5:26
- Changed state: WontFix
from jquery-translate.
Related Issues (20)
- Bing won't translate HOT 5
- bing translator and non-well-formed html HOT 24
- support for Google v2 API HOT 25
- Line 462 in Code Trunk Bug. from should be form HOT 1
- How to Remove Openning and Clsong div's in Translate Method Call HOT 1
- the // in http:// is interpreted as comment-line HOT 1
- The Translator is currently not translating anything. HOT 1
- Bing API ID Throwing Error HOT 4
- By setting parallel parameter to true doesn't work, is still working as parallel: false HOT 1
- getting error while loading bingAPI HOT 2
- Uncaught TypeError: Cannot call method 'replace' of undefined HOT 1
- Some fix for correct work with BING HOT 3
- No works for me and no translation , Can you help me please ?
- google.language.callbacks issue(?) HOT 1
- (414) Request-URI Too Large for content length > 2K characters
- Infinite loop when translating certain html
- new fix for use class notranslate
- Patch for /tags/1.4.1/src/jquery.translate-core.js
- Won't Work in Firefox or Chrome on Windows
- Provide a code sample of how to load the plugin
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-translate.