Jump to content

using new tag attributes


nepenthe

Recommended Posts

hello..I need to use different tag attributes for my multi language web project.for example

 

<span textTranslation="welcome"></span>

 

when i call the javascript function, it searches and finds the the tags with textTranslation attribute.and then  changes the innerHTML of that tag with appropriate translation..it works well..

 

but what i want to ask is using undefined atrributes is a problem or not? also html validators can't recognize that attribute and give errors.

 

what do you recommend?

thanks

Link to comment
Share on other sites

This sounds like an ideal candidate for an ajax app....

 

How ever may I susggest this...

 

just give each span that is going to be translated a class

 

Like so

 

<span class="translate">Welcome</span>

 

NOW by having some text within the span when the page loads this will help you transloation app (it can always refer to englisjh in this case);

 

Now you can do this in js

 

function translateSpans()
{
els = document.getElementsByTagName('span);
var text = null; 
for(var i = 0; i < els.length; i++)
{
  if (els[i].className == 'translate')
  {
   text = els[i].innerHTML;
   // do the bit that finds the translation.
  els[i].innerHTML = 'text found in translation look up';
  }
}
}

 

all that will valdiate and then you won't need to worry about undefined attributes again!!!!

Link to comment
Share on other sites

thanks for the answers..

 

I think this method is better than mine :) but I'm not sure, is it really "bad" to have classes that do nothing?

 

I also have another question..I use xml files for language translations. I make an ajax request to get the translations to an array at the beginning while the page not loaded completely..At this time, visitors see the span's innerHTML for example: firstname,welcome, or err_invalid_name...

 

Do you think should I display a loading info or making "translate" classes hidden in this period is a good solution?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.