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.

Modify or translate the toolbar texts

Go down

Tutorial Modify or translate the toolbar texts

Post by Ange Tuteur August 14th 2015, 10:25 am

Modify or translate the toolbar texts


This trick will teach you how to modify the texts that display on the toolbar. Maybe because you want to change the wording or translate it into your language. Wink

Modify or translate the toolbar texts Captur65


Modify or translate the toolbar texts 09615110 Installing the JavaScript


The installation is rather simple as only a single script is needed. Go to Administration Panel > Modules > JavaScript codes management and create a new script.

Title : Toolbar Text
Placement : In all the pages
Code:
$(function() {
  var toolbar_alias = {
 
    Share : 'Share',
    Login : 'Login',
    Register : 'Register',
    Welcome : 'Welcome',
    Notifications : 'Notifications',
 
    See_my_profile : 'View profile',
    Edit_profile : 'Edit profile',
    All_Topics : 'My topics',
    All_Messages : 'My posts',
    js_topics_followed : 'Watched topics',
    Admin_panel : 'Administration Panel',
    Logout : 'Log out',
 
    Notif_see_all : 'See all the notifications',
    Notif_priv_msg : 'You have received a <a href="/privmsg?folder=inbox&amp;nid=%(nid)s">private message</a> from <a href="/u%(id)d">%(name)s</a>',
    Notif_report : '<a href="/u%(id)d">%(name)s</a> has created a <a href="/report?nid=%(nid)s">message report</a>',
    Notif_friend_req : 'You have received a <a href="/profile?mode=editprofile&amp;nid=%(nid)s&amp;page_profil=friendsfoes">friend request</a> from <a href="/u%(id)d">%(name)s</a>',
    Notif_group_req : '<a href="/u%(id)d">%(name)s</a> has made a request to join the group <a href="/g%(group_id)d-%(group_url_name)s?nid=%(nid)s">%(group_name)s</a>',
    Notif_friend_con : '<a href="/u%(id)d">%(name)s</a> has connected',
    Notif_wall_msg : '<a href="/u%(id)d">%(name)s</a> has just written a message on <a href="/u%(self)dwall?nid=%(nid)s">your wall</a>',
    Notif_abuse : '<a href="/admin/index.forum?mode=active&amp;nid=%(nid)s&amp;part=misc&amp;sub=support">An abuse</a> was reported',
    Notif_topic_watch : '<a href="/u%(id)d">%(name)s</a> wrote a message <a href="/t%(topic_id)d-%(topic_name)s?nid=%(nid)s#%(post_id)d">in a watched topic</a>',
    Notif_topic_watch_p : '<a href="/u%(id)d">%(name)s</a> wrote a message <a href="/t%(topic_id)dp%(start)d-%(topic_name)s?nid=%(nid)s#%(post_id)d">in a watched topic</a>',
    Notif_topic_watch_guest : 'A guest wrote a message in <a href="/t%(topic_id)d-%(topic_name)s?nid=%(nid)s#%(post_id)d">a topic you watch</a>',
    Notif_topic_watch_p_guest : 'A guest wrote a message in <a href="/t%(topic_id)dp%(start)d-%(topic_name)s?nid=%(nid)s#%(post_id)d">a topic you watch</a>',
    Notif_mention : '<a href="/u%(id)d">%(name)s</a> tagged you in <a href="/t%(topic_id)dp%(start)d-%(topic_name)s?nid=%(nid)s#%(post_id)d">a topic</a>',
    Notif_hashtag : 'The keyword <a href="/tags/%(tag)s">#%(tag)s</a> has been tagged in <a href="/t%(topic_id)dp%(start)d-%(topic_name)s?nid=%(nid)s#%(post_id)d">a topic</a>.',
 
    All_PMs : 'My private messages',
    No_assigned_rank : 'No special rank assigned',
    Posts : 'Posts',
    PMs : 'PMs',
    Reputation : 'Reputation'
 
  },i;
 
  if (window._lang) for (i in toolbar_alias) window._lang[i] = toolbar_alias[i];
});

The script in its current state only contains the original English translation. Please read the next section to learn how to change these texts.


Modify or translate the toolbar texts 09615110 Modifying the texts


To change the current text in the script you will need to modify the properties of the toolbar_alias object. In there you will see phrases such as :
Code:
    Share : 'Share',
    Login : 'Login',
    Register : 'Register',
    Welcome : 'Welcome',
    Notifications : 'Notifications',

To the left of the colon is the alias, this SHOULD NOT be modified. The content which you should modify is to the right of the colon, between the single quotes. ( This is known as a "Text String" )

So if I wanted to change "Welcome" to "Logged in as" all I need to do is change the texts in the welcome string like so :
Code:
Welcome : 'Logged in as',

Then just save the script and the texts should be changed on the welcome menu. Smile


Modify or translate the toolbar texts 10-10-13 Escaping special characters


Also, one important thing to note is the usage of similar quotes inside a text string. Since we're using single quotes to define a string, it's imperative that you escape any single quotes you use with the special escape character : \

Here's a quick example to demonstrate escaping a quote.
Code:
No_assigned_rank : 'You don\'t have a rank',

As you can see in the example above I wrote don\'t. We have to escape this single quote, because if we don't it will end the string early and break the script. Now that you have this in mind you should have no problems changing the texts. Very Happy


Modify or translate the toolbar texts 09615110 Notification variables


Lastly, one important thing to note is that you can change the structure of the notification texts as well. This is useful, but you should also be careful when editing as there are important variables ! You may see something similar to this in the notifications : %(name)s

That is a variable that's replaced with the user's name, it should not be edited unless you know what you're doing. You can move them around of course, but just be careful when editing them. For reference, I'll leave a list of the variables below. Wink

VariableDescription
%(id)dThe id of the user who sent the notification.
%(self)dYour user id.
%(name)sThe name of the user who sent the notification.
%(post_id)dThe post id of a referenced topic.
%(start)dThe page id of a referenced topic.
%(topic_id)dThe id of a referenced topic.
%(topic_name)sThe name of a referenced topic.
%(group_id)dThe id of a referenced group.
%(group_url_name)sThe slugified URL of a referenced group.
%(group_name)sThe name of a referenced group.
%(tag)sThe hashtag that was tagged in a topic.
%(nid)sThe ID of the notification.


With all this in mind, you should now be able to change any of the texts that you want on the toolbar. Of course if you need any help you're free to ask on the support. thumleft

Ange Tuteur
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

SarkZKalie likes this post

Back to top Go down

Back to top

- Similar topics

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