Coder Social home page Coder Social logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 12, 2024

Original comment by balazs.endresz on 10 Feb 2009 at 5:26

  • Changed state: WontFix

from jquery-translate.

Related Issues (20)

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.