Jamroom Logo Jamroom 5 Core
is now Open Source!
Follow Jamroom on Twitter!


Including additional Libraries in your Module Index Creating custom Jamroom Ranking System modes for your module

Using Language Strings to support multiple languages

The Jamroom Control Panel is capable of being displayed in almost any language, and if you would like your module to be able to be translated as well, you will want to be sure your Control Panel config files use the proper language strings.  By default, when Jamroom loads a page in the Control Panel, it loads the following language file(s):

    language/english.lang.php (loaded by default on all requests)

    language/(user_language).lang.php  (loaded "on top" of english.lang.php to provide translations into user's preferred language - only done if user is using a language other then English).

So we can see that English gets set as the "default" language for the Control Panel.  If you would like to add language strings into this default english.lang.php file, you would simply create your own within the "language" directory of your module.  So for our jrYouTube module we would have:

    modules/jrYouTube/language/english.lang.php

Since our jrYouTube module is a very simple module, we're not going to have many language strings, but it is important that we use the name of our module as the language "key" - that way our language strings do not inadvertently overwrite any existing language strings.  So in our "english.lang.php" file we would have:

<?php
/**
 * Jamroom jrYouTube module English Language file
 * @copyright 2009 by Talldude Networks LLC
 * @author Brian Johnson - bigguy@jamroom.net
 */
$language['jrYouTube'][1] = 'YouTube Videos';
$language['jrYouTube'][2] = 'Create Video';
$language['jrYouTube'][3] = 'Delete Video';
$language['jrYouTube'][4] = 'YouTube ID';
$language['jrYouTube'][5] = 'YouTube Category';
$language['jrYouTube'][6] = 'Invalid YouTube ID - please enter a valid ID';
$language['jrYouTube'][7] = 'The YouTube Video was successfully created!';
$language['jrYouTube'][8] = 'There are no YouTube Videos to delete!';
$language['jrYouTube'][9] = 'Are you sure?';
$language['jrYouTube'][10] = 'The YouTube Video was successfully deleted';

As you can see we are only defining a few different language strings, but it illustrates how language strings are added in to our file.

This will now allow us to revisit our Control Panel file we created earlier and update it to use our new language strings:

<?php
/**
 * Jamroom jrYouTube Control Panel options plugin
 * @copyright 2008 by Talldude Networks LLC.
 * @author Brian Johnson - bigguy@jamroom.net
 */
defined('IN_JAMROOM') or exit();

function jrYouTubeMenu(&$_user)
{
    global $language;
    if (!isset($GLOBALS['JR_MENU_SECTIONS']['section_jrYouTubeMenu'])) {
        return(true);
    }
    if ($_user['quota_id'] < 0 || $_user['quota_jryoutube_access'] != 'yes') {
        return(false);
    }
    jmTextBanner($language['jrYouTube'][1],'false','false','false','section_jrYouTubeMenu');
    jmButton($language['jrYouTube'][2],'jrYouTube.php?mode=youtube_add','youtube_create');
    jmButton($language['jrYouTube'][3],'jrYouTube.php?mode=youtube_del','youtube_delete');
    jmTextBannerEnd();
    return(true);
}
?>

You can see we have replaced the 3 visible Text Strings in the control panel with their language file entries - this will allow the language to be changed without having to make any modifications to our module.

We have also added one more entry into our jrYouTubeMenu function:

global $language;

This gives us access to the $language array that was created in our english.lang.php file.  In order for PHP to have access to the $language entries we added in our language file, we must use the keyword "global" in our function to let PHP know we want local function access to that array.

 

Including additional Libraries in your Module Including additional Libraries in your Module page 15 of 23 Creating custom Jamroom Ranking System modes for your module Creating custom Jamroom Ranking System modes for your module
Solutions Products Support Community Company
Social Media Platform
Social Networking Software
Musician Website Manager
Community Builder
Jamroom 5
Jamroom 5 Modules
Jamroom Marketplace
Support Forum
Documentation
Support Center
Contact Support
Community Forum
Member Sites
Developers
About Us
Contact Us
Privacy Policy
©2003 - 2024 The Jamroom Network