Skip to content

Commit

Permalink
Introduced the $vocab_override config variable, allowing MRBS text st…
Browse files Browse the repository at this point in the history
…rings to be customised without editing the lang files, thus making it easier to upgrade when new versions of MRBS are released. Thanks to dwpoon. See SF ID 3499943

git-svn-id: http://svn.code.sf.net/p/mrbs/code/mrbs/trunk@2273 25f7e783-145e-4f2d-a9f8-dd7182bfe9c7
  • Loading branch information
cimorrison committed Mar 9, 2012
1 parent 5c9ecc3 commit 86f906e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 24 deletions.
20 changes: 14 additions & 6 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ PostgreSQL presents some problems in PHP when trying to process the results
of a query in a database independent way, so it is more convenient to use a
smallint instead of a boolean in PostgreSQL.]

Text descriptions are looked for in the lang files with the tag room.column_name,
Text descriptions are set in the config file using the $vocab_override variable
using the appropriate language(s) and with the tag room.column_name,
eg room.coffee_machine, or users.phone enabling translations to be provided.
If not present, the column name will be used for labels etc. If you are adding
columns to the entry and repeat tables then you only need to add the
Expand All @@ -201,9 +202,9 @@ coffee_machine tinyint(1)

to the room table and add the line

vocab["room.coffee_machine"] = "Coffee machine";
$vocab_override['en']['room.coffee_machine'] = "Coffee machine";

to the lang.en file and similarly for other languages as required. MRBS
to the config file and similarly for other languages as required. MRBS
should then do the rest and display your coffee machine field on the room
pages.

Expand Down Expand Up @@ -433,9 +434,16 @@ CHANGING TEXT STRINGS
---------------------------------------------------------------------------

All the text strings used by MRBS, except those used on the Help page, are held in a
series of lang.* files, for example lang.en for English, or lang.fr for French. If
you want to change some of the text strings used by MRBS, for example change "Room"
to "Computer", then look for the appropriate string in the lang files and edit it.
series of lang.* files, for example lang.en for English, or lang.fr for French. They
are overridden by the $vocab_override array in the config file. If you want to change
some of the text strings used by MRBS, for example change "Room" to "Computer", then
look for the appropriate string in the lang files, remember its tag and set the
$vocab_override variable in the config file. For example

$vocab_override['en']['ctrl_click'] = "Use Control-Click to select more than one computer";

Doing it this way, rather than editing the lang files, will mean that when you upgrade to
the next version of MRBS you will not have to re-edit the lang files.


INTERNATIONALISATION
Expand Down
8 changes: 8 additions & 0 deletions UPGRADE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ the upgraded database. You may therefore choose to make a copy of the
database for test purposes and check that the upgrade process works before
performing the upgrade on your production database.

Upgrading from prior MRBS 1.4.9
===============================

MRBS now supports the $vocab_override config variable. See
systemdefaults.inc.php for more details. If you have customised your version
of MRBS by editing the lang files, you are advised to use $vocab_override instead.
This will make future upgrades easier.


Upgrading from prior MRBS 1.4.6
===============================
Expand Down
12 changes: 7 additions & 5 deletions web/edit_area_room.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
// in MySQL.
//
// You can put a description of the column that will be used as the label in
// the form in the appropriate lang file(s) using the tag 'room.[columnname]'.
// the form in the $vocab_override variable in the config file using the tag
// 'room.[columnname]'.
//
// For example if you want to add a column specifying whether or not a room
// has a coffee machine you could add a column to the room table called
// 'coffee_machine' of type tinyint(1), in MySQL, or smallint in PostgreSQL.
// Then in the appropriate lang file(s) you would add the line
// Then in the config file you would add the line
//
// vocab["room.coffee_machine"] = "Coffee machine"; // or appropriate translation
// $vocab_override['en']['room.coffee_machine'] = "Coffee machine"; // or appropriate translation
//
// If MRBS can't find an entry for the field in the lang file, then it will use
// the fieldname, eg 'coffee_machine'.
// If MRBS can't find an entry for the field in the lang file or vocab overrides, then
// it will use the fieldname, eg 'coffee_machine'.

require_once "defaultincludes.inc";
require_once "mrbs_sql.inc";
Expand Down
12 changes: 6 additions & 6 deletions web/edit_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
// in MySQL.
//
// You can put a description of the column that will be used as the label in
// the form in the appropriate lang file(s) using the tag 'entry.[columnname]'.
// (Note that it is not necessary to add a 'repeat.[columnname]' tag. The
// entry tag is sufficient.)
// the form in the $vocab_override variable in the config file using the tag
// 'entry.[columnname]'. (Note that it is not necessary to add a
// 'repeat.[columnname]' tag. The entry tag is sufficient.)
//
// For example if you want to add a column recording the number of participants
// you could add a column to the entry and repeat tables called 'participants'
// of type int. Then in the appropriate lang file(s) you would add the line
//
// $vocab["entry.participants"] = "Participants"; // or appropriate translation
// $vocab_override['en']['entry.participants'] = "Participants"; // or appropriate translation
//
// If MRBS can't find an entry for the field in the lang file, then it will use
// the fieldname, eg 'coffee_machine'.
// If MRBS can't find an entry for the field in the lang file or $vocab_override,
// then it will use the fieldname, eg 'coffee_machine'.


require_once "defaultincludes.inc";
Expand Down
30 changes: 23 additions & 7 deletions web/language.inc
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ $rtl_languages = array('he');
// Get a default set of language tokens, you can change this if you like.
// Always include English as the fallback language, in case the selected language
// is missing some translated tokens
include "lang.en";
// include_once just to avoid reloading the 'en' file
include_once "lang." . $default_language_tokens;

set_vocab('en');
set_vocab($default_language_tokens);

// Get first default set of language tokens for emails.
$need_to_send_mail = ($mail_settings['admin_on_bookings'] or
Expand All @@ -367,7 +365,7 @@ $need_to_send_mail = ($mail_settings['admin_on_bookings'] or
if ($need_to_send_mail)
{
$web_vocab = $vocab; // Save $vocab before it gets overwritten
include "lang." . $mail_settings['admin_lang'];
set_vocab($mail_settings['admin_lang']);
$mail_vocab = $vocab;
$vocab = $web_vocab; // Restore $vocab
}
Expand Down Expand Up @@ -437,7 +435,7 @@ if (!$disable_automatic_language_changing || $cli_mode)
}
if (file_exists($lang_file))
{
include $lang_file;
set_vocab($lang);
$locale = $lang;
// Work out if we're using a RTL language. This variable is used
// globally so that we can include the correct stylesheet
Expand All @@ -463,7 +461,7 @@ if (!$disable_automatic_language_changing || $cli_mode)
}
if (file_exists($lang_file))
{
include $lang_file;
set_vocab(substr($lang,0,2));
// If we have found a translation, update the locale to match
$locale = $lang;
break;
Expand Down Expand Up @@ -705,6 +703,24 @@ function get_datatable_lang()
}


function set_vocab($lang)
{
global $vocab, $vocab_override;

$lang = strtolower($lang);
// Get the standard language tokens
include "lang.$lang";
// Apply any site overrides
if (isset($vocab_override[$lang]))
{
foreach ($vocab_override[$lang] as $tag => $str)
{
$vocab[$tag] = $str;
}
}
}


function get_charset()
{
return 'utf-8';
Expand Down
13 changes: 13 additions & 0 deletions web/systemdefaults.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,19 @@
// Language selection when run from the command line
$cli_language = "en";

// Vocab overrides
// ---------------

// You can override the text strings that appear in the lang.* files by setting
// $vocab_override[LANG][TOKEN] in your config file, where LANG is the language,
// for example 'en' and TOKEN is the key of the $vocab array. For example to
// alter the string "Meeting Room Booking System" in English set
//
// $vocab_override['en']['mrbs'] = "My Resource Booking System";
//
// Applying vocab overrides in the config file rather than editing the lang files
// mean that your changes will be preserved whenb you upgrade to the next version of
// and you won't have to re-edit the lang file.

/*************
* Reports
Expand Down

0 comments on commit 86f906e

Please sign in to comment.