Commit eea2e6be authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I425fbdaa,Ifb58ac4f

* changes:
  Use the plural form translations for selected strings (bug #901051)
  Modify get_string to take plural forms (bug #901051)
parents de9a24e7 526e4698
......@@ -70,6 +70,9 @@ $next .= (strpos($next, '?') === false ? '?' : '&') . 'folder=' . $status['basef
$SESSION->set('unzip', false);
$message = get_string('extractfilessuccess', 'artefact.file', $status['folderscreated'], $status['filescreated']);
$message = get_string('createdtwothings', 'artefact.file',
get_string('nfolders', 'artefact.file', $status['folderscreated']),
get_string('nfiles', 'artefact.file', $status['filescreated'])
);
print_extractprogress_footer($message, $next);
......@@ -154,7 +154,11 @@ function unzip_artefact_submit(Pieform $form, $values) {
$status = $file->extract();
$SESSION->add_ok_msg(get_string('extractfilessuccess', 'artefact.file', $status['folderscreated'], $status['filescreated']));
$message = get_string('createdtwothings', 'artefact.file',
get_string('nfolders', 'artefact.file', $status['folderscreated']),
get_string('nfiles', 'artefact.file', $status['filescreated'])
);
$SESSION->add_ok_msg($message);
$redirect = $from . (strpos($from, '?') === false ? '?' : '&') . 'folder=' . $status['basefolderid'];
redirect($redirect);
}
......@@ -337,7 +337,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
warn += get_string('defaultprofileicon') + ' ';
}
if (self.filedata[id].attachcount > 0) {
warn += get_string('fileattached', self.filedata[id].attachcount) + ' ';
warn += get_string('fileattachedtoportfolioitems', self.filedata[id].attachcount) + ' ';
}
if (self.filedata[id].viewcount > 0) {
warn += get_string('fileappearsinviews') + ' ';
......
......@@ -83,7 +83,10 @@ $string['File'] = 'File';
$string['fileadded'] = 'File selected';
$string['filealreadyindestination'] = 'The file you moved is already in that folder';
$string['fileappearsinviews'] = 'This file appears in one or more of your pages.';
$string['fileattached'] = 'This file is attached to %s other item(s) in your portfolio.';
$string['fileattachedtoportfolioitems'] = array(
0 => 'This file is attached to %s other item in your portfolio.',
1 => 'This file is attached to %s other items in your portfolio.',
);
$string['fileremoved'] = 'File removed';
$string['files'] = 'files';
$string['Files'] = 'Files';
......@@ -228,7 +231,10 @@ $string['noimagesfound'] = 'No images found';
$string['profileiconaddedtoimagesfolder'] = "Your profile picture has been uploaded to your '%s' folder.";
$string['profileiconsetdefaultnotvalid'] = 'Could not set the default profile picture, the choice was not valid';
$string['profileiconsdefaultsetsuccessfully'] = 'Default profile picture set successfully';
$string['profileiconsdeletedsuccessfully'] = 'Profile picture(s) deleted successfully';
$string['nprofilepictures'] = array(
'Profile picture',
'Profile pictures',
);
$string['profileiconsnoneselected'] = 'No profile pictures were selected to be deleted';
$string['onlyfiveprofileicons'] = 'You may upload only five profile pictures';
$string['or'] = 'or';
......@@ -248,7 +254,15 @@ $string['wrongfiletypeforblock'] = 'The file you uploaded was not the correct ty
// Unzip
$string['Contents'] = 'Contents';
$string['Continue'] = 'Continue';
$string['extractfilessuccess'] = 'Created %s folders and %s files.';
$string['nfolders'] = array(
'%s folder',
'%s folders',
);
$string['nfiles'] = array(
'%s file',
'%s files',
);
$string['createdtwothings'] = 'Created %s and %s.';
$string['filesextractedfromarchive'] = 'Files extracted from archive';
$string['filesextractedfromziparchive'] = 'Files extracted from Zip archive';
$string['fileswillbeextractedintofolder'] = 'Files will be extracted into %s';
......
......@@ -130,7 +130,7 @@ class PluginArtefactFile extends PluginArtefact {
'editfile',
'editfolder',
'fileappearsinviews',
'fileattached',
'fileattachedtoportfolioitems',
'filewithnameexists',
'folderappearsinviews',
'foldercontainsprofileicons',
......
......@@ -283,7 +283,9 @@ function settings_submit_delete(Pieform $form, $values) {
db_commit();
$SESSION->add_ok_msg(get_string('profileiconsdeletedsuccessfully', 'artefact.file'));
$SESSION->add_ok_msg(
get_string('filethingdeleted', 'artefact.file', get_string('nprofilepictures', 'artefact.file', count($icons)))
);
}
else {
$SESSION->add_info_msg(get_string('profileiconsnoneselected', 'artefact.file'));
......
......@@ -28,11 +28,21 @@ function get_string(s) {
return '[[[' + s + ((args.length > 0) ? ('(' + args.join(',') + ')') : '') + ']]]';
}
var str = strings[s];
// @todo Need to sprintf these strings properly.
for (var i = 0; i < args.length; i++) {
str = str.replace('%s',args[i]);
if (typeof(str) == 'object') {
var index = 0;
if (args.length > 0 && typeof(plural) == 'function') {
index = plural(parseInt(args[0]));
if (typeof(index) == 'boolean') {
index = index ? 1 : 0;
}
}
if (typeof(str[index]) != 'string') {
return '[[[' + s + ((args.length > 0) ? ('(' + args.join(',') + ')') : '') + ']]]';
}
str = str[index];
}
return str;
var i = 0;
return str.replace(/%((%)|s)/g, function (m) { return m[2] || args[i++]; });
}
// Expects an image/css path to fetch url for (requires config.theme[] to be
......
......@@ -46,3 +46,13 @@ $string['strftimew3cdatetime'] = '%%Y-%%m-%%dT%%H:%%M:%%S%%z';
$string['strftimew3cdate'] = '%%Y-%%m-%%d';
$string['thislanguage'] = 'English';
$string['locales'] = 'en_US.utf8,en_GB.utf8,en,english-us,english-uk,english';
// Rule to choose from the language's plural forms.
// See the gettext manual, http://www.gnu.org/s/hello/manual/gettext/Plural-forms.html
// For language packs converted from PO format, the following strings and function will be
// automatically generated from the expression in the PO file's "Plural-Forms:" header.
$string['pluralrule'] = 'n != 1';
$string['pluralfunction'] = 'plural_en_utf8';
function plural_en_utf8($n) {
return (int) $n != 1;
}
......@@ -110,7 +110,10 @@ $string['youhavenottaggedanythingyet'] = 'You have not tagged anything yet';
$string['mytags'] = 'My Tags';
$string['Tag'] = 'Tag';
$string['itemstaggedwith'] = 'Items tagged with "%s"';
$string['numitems'] = '%s items';
$string['nitems'] = array(
'%s item',
'%s items',
);
$string['searchresultsfor'] = 'Search results for';
$string['alltags'] = 'All Tags';
$string['sortalpha'] = 'Sort tags alphabetically';
......
......@@ -469,7 +469,7 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo
// First check all the normal locations for the string in the current language
$result = get_string_local($langstringroot . $langdirectory, $lang . '/' . $section . '.php', $identifier);
if ($result !== false) {
return $replacefunc($result, $variables);
return $replacefunc($result, $variables, $lang);
}
// If the preferred language was English (utf8) we can abort now
......@@ -484,7 +484,7 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo
if ($parentlang = get_string_from_file('parentlanguage', $langfile)) {
$result = get_string_local(get_language_root($parentlang) . 'lang/', $parentlang . '/' . $section . '.php', $identifier);
if ($result !== false) {
return $replacefunc($result, $variables);
return $replacefunc($result, $variables, $parentlang);
}
}
}
......@@ -1057,10 +1057,20 @@ function current_language() {
* Helper function to sprintf language strings
* with a variable number of arguments
*
* @param string $string raw string to use
* @param mixed $string raw string to use, or an array of strings, one for each plural form
* @param array $args arguments to sprintf
* @param string $lang The language
*/
function format_langstring($string,$args) {
function format_langstring($string, $args, $lang='en.utf8') {
if (is_array($string) && isset($args[0]) && is_numeric($args[0])) {
// If there are multiple strings here, there must be one for each plural
// form in the language. The first argument is passed into the plural
// function, which returns an index into the array of strings.
$pluralfunction = get_string_location('pluralfunction', 'langconfig', array(), 'raw_langstring', $lang);
$index = function_exists($pluralfunction) ? $pluralfunction($args[0]) : 0;
$string = isset($string[$index]) ? $string[$index] : current($string);
}
return call_user_func_array('sprintf',array_merge(array($string),$args));
}
......
......@@ -327,6 +327,7 @@ EOF;
$stringjs = '<script type="text/javascript">';
$stringjs .= 'var strings = ' . json_encode($strings) . ';';
$stringjs .= "\nfunction plural(n) { return " . get_string('pluralrule', 'langconfig') . "; }\n";
$stringjs .= '</script>';
// stylesheet set up - if we're in a plugin also get its stylesheet
......
......@@ -2,7 +2,7 @@
<div class="sidebar-content tagblock">
{if $sbdata.tags}
{foreach from=$sbdata.tags item=tag}
<a class="tag"{if $tag->size} style="font-size: {$tag->size}em;"{/if} href="{$WWWROOT}tags.php?tag={$tag->tag|urlencode|safe}" title="{str tag=numitems arg1=$tag->count}">{$tag->tag|str_shorten_text:20}</a>
<a class="tag"{if $tag->size} style="font-size: {$tag->size}em;"{/if} href="{$WWWROOT}tags.php?tag={$tag->tag|urlencode|safe}" title="{str tag=nitems arg1=$tag->count}">{$tag->tag|str_shorten_text:20}</a>
{/foreach}
{else}
{str tag=youhavenottaggedanythingyet}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment