The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Replace post time text from English to other

5 posters

Go down

Solved Replace post time text from English to other

Post by Kami-sama January 5th 2015, 7:03 pm

Hello!

So, in my forum (version phpBB2) the language of the forum is not English, but some text is yet shown in English. While changing it in "online" table, I used javascript and replace command. For example:
Code:
<script type="text/javascript">
document.getElementById('buve').innerHTML=document.getElementById('buve').innerHTML.replace('Members connected during last 24 hours','Paskutinę parą čia matytos sielos');
</script>

But, yet that does not work when I try to change English words next to latest post time (Today, Yesterday). Well, tbh, it does work, but only for the first row (first forum latest post time). If I place the ID in other places, where logically it should work - it does not. I assume there should be some commands like replaceall or smth?

If you have any questions do ask!
If there is an option, to pitch translations for forumotion, do tell me where!
If you have any solutions for that I hope you will share them Wink

If this topic already exists do link me to it!
Thank you in advance!


Last edited by Kami-sama on January 6th 2015, 2:54 pm; edited 1 time in total
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Replace post time text from English to other

Post by Ange Tuteur January 6th 2015, 12:52 am

Hi @Kami-sama,

The problem is that an ID is meant to be unique to 1 element. For a collection of elements, use a classname instead. Here's an example using a for loop to replace the text on elements with the classname "lastpostText" :

Display > Templates > General > index_box Edit

Find :
Code:
<span class="gensmall">{catrow.forumrow.LAST_POST}</span>

Replace by :
( or add class "lastpostText" )
Code:
<span class="gensmall lastpostText">{catrow.forumrow.LAST_POST}</span>

Save and publish. Add


Then go to  Modules > JavaScript code management > Create a new script

Title : Your choice
Placement : In the homepage
Code:
$(function() {
  for (var i=0, s=document.getElementsByTagName('SPAN'); i<s.length; i++) {
    if (/lastpostText/.test(s[i].className)) {
      translate(/Today/, 'todaytext');
      translate(/Yesterday/, 'yestertext');
    }
  }
  function translate(oldText,newText) { if (oldText.test(s[i].innerHTML)) s[i].innerHTML = s[i].innerHTML.replace(oldText,newText) };
});
The above is an example of text replacement on multiple elements, you can also use the jQuery each() method if you like. Wink


For the board language, some are partial translations. As far as volunteer translations go, I'd try and contact Buttercup about that, as she works directly with the company.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Replace post time text from English to other

Post by Michael_vx January 6th 2015, 7:29 am

@Ange Tuteur
can i jump in Very Happy
i like to ask
if this way can be used to change the way of the date style
like some how on forums who Edit templates the date appear like this
M/D/Y and it should be D/M/Y this one in topics at most also hid or make the date shorter in sub forums because i still did not understand the example yet
and I apologize for jumping in here
Michael_vx
Michael_vx
Forumember

Male Posts : 664
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: Replace post time text from English to other

Post by _Twisted_Mods_ January 6th 2015, 7:41 am

Michael_vx wrote:@Ange Tuteur
can i jump in Very Happy
i like to ask
if this way can be used to change the way of the date style
like some how on forums who Edit templates the date appear like this
M/D/Y and it should be D/M/Y this one in topics at most also hid or make the date shorter in sub forums because i still did not understand the example yet
and I apologize for jumping in here

you can change date style in your profile options
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2108
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: Replace post time text from English to other

Post by Michael_vx January 6th 2015, 7:57 am

@_Twisted_Mods_
the problem im talking about only with themes made by template of the date show as M/D/Y instead of D/M/Y
and i dont think the shorting date is from profile settings Very Happy
am i right ?
Michael_vx
Michael_vx
Forumember

Male Posts : 664
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: Replace post time text from English to other

Post by Kami-sama January 6th 2015, 2:26 pm

Ange Tuteur wrote:Hi @Kami-sama,

The problem is that an ID is meant to be unique to 1 element. For a collection of elements, use a classname instead. Here's an example using a for loop to replace the text on elements with the classname "lastpostText" :

Display > Templates > General > index_box Edit

Find :
Code:
<span class="gensmall">{catrow.forumrow.LAST_POST}</span>

Replace by :
( or add class "lastpostText" )
Code:
<span class="gensmall lastpostText">{catrow.forumrow.LAST_POST}</span>

Save and publish. Add


Then go to  Modules > JavaScript code management > Create a new script

Title : Your choice
Placement : In the homepage
Code:
$(function() {
  for (var i=0, s=document.getElementsByTagName('SPAN'); i<s.length; i++) {
    if (/lastpostText/.test(s[i].className)) {
      translate(/Today/, 'todaytext');
      translate(/Yesterday/, 'yestertext');
    }
  }
  function translate(oldText,newText) { if (oldText.test(s[i].innerHTML)) s[i].innerHTML = s[i].innerHTML.replace(oldText,newText) };
});
The above is an example of text replacement on multiple elements, you can also use the jQuery each() method if you like. Wink


For the board language, some are partial translations. As far as volunteer translations go, I'd try and contact Buttercup about that, as she works directly with the company.

Hey! Thank you for your suggestions I will try them out Wink

About the ID. I know it should be one of the kind, but lets say, you put ID in front of everything, so that replacement would happen when all the table is assembled. Then it should replace all? I think when I was working on online table, I tried to replace a space and then all the spaces in the div with that ID were replaced. Am I hallucinating or that might have happened? Very Happy


EDIT: so I've tried it and it works like a charm! Thank you a lot!
One question from that though, why do you need to tick "Home page", why does ticking "all pages" don't work? You would imagine that "all page" means all pages ;D
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Replace post time text from English to other

Post by Ange Tuteur January 7th 2015, 1:34 am

You're welcome. Smile

Technically if you apply an ID to the parent, and then replace the HTML content it should work. Using #main-content would be a good example.

Since the classname lastpostText was applied to only the index_box template ( the homepage ), we wouldn't want to run the same script where it doesn't exist. It wont cause any errors, but it'll iterate over all SPAN elements each time.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Replace post time text from English to other

Post by Base January 7th 2015, 12:18 pm

Marked as Solved => Archived
Base
Base
Forumaster

Male Posts : 10386
Reputation : 1695
Language : English and French
Location : United Kingdom, England

http://forumotionhub.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum