Disable languages in the language options dropdown

171 views
Skip to first unread message

jum...@gmail.com

unread,
Mar 15, 2021, 3:12:57 PM3/15/21
to ResourceSpace
I'm trying to build a RS site in two languages: English and French.

I don't need all the other language options, nor the distinction between British and American English. So I would prefer to hide all the other language options,.

Can't seem to find where to delete languages, is that even possible? I found the following in the default config file, but that seems mostly for changing the names of these languages. Including only British English and French won't hide the other languages.

My quick and dirty solution has been to delete the names of the languages below so they end up as white space in the dropdown.

# Available languages
# If $defaultlanguage is not set, the brower's default language will be used instead
$defaultlanguage="en"; # default language, uses ISO 639-1 language codes ( en, es etc.)
$languages["en"]="British English";
$languages["en-US"]="American English";
$languages["ar"]="العربية";
$languages["id"]="Bahasa Indonesia"; # Indonesian
$languages["ca"]="Català"; # Catalan
$languages["zh-CN"]="简体字"; # Simplified Chinese
$languages["da"]="Dansk"; # Danish
$languages["de"]="Deutsch"; # German
$languages["el"]="Ελληνικά"; # Greek
$languages["es"]="Español"; # Spanish
$languages["es-AR"]="Español (Argentina)";
$languages["fr"]="Français"; # French
$languages["hr"]="Hrvatski"; # Croatian
$languages["it"]="Italiano"; # Italian
$languages["jp"]="日本語"; # Japanese
$languages["nl"]="Nederlands"; # Dutch
$languages["no"]="Norsk"; # Norwegian
$languages["pl"]="Polski"; # Polish
$languages["pt"]="Português"; # Portuguese
$languages["pt-BR"]="Português do Brasil"; # Brazilian Portuguese
$languages["ru"]="Русский язык"; # Russian
$languages["sk"]="Slovenčina"; # Slovak
$languages["fi"]="Suomi"; # Finnish
$languages["sv"]="Svenska"; # Swedish


Mike Perry

unread,
Mar 16, 2021, 10:08:41 AM3/16/21
to ResourceSpace
Don't modify the config.default.php file. Copy the the available languages section and add the modified version to config.php like this:

# Available languages
# If $defaultlanguage is not set, the brower's default language will be used instead
$defaultlanguage="en-US"; # default language, uses ISO 639-1 language codes ( en, es etc.)
#sets default to US English
$languages["en-US"]="American English";
$languages["fr"]="Français"; # French

Or try adding this line to config.php:

# Disable language selection options (Includes Browser Detection for language)
$disable_languages=false;

Manual changes you make to config.default.php will be lost when you upgrade.

jum...@gmail.com

unread,
Mar 16, 2021, 10:22:57 AM3/16/21
to ResourceSpace
Thanks! Yes, I wasn't clear in my post, but I tried adding those settings to the config.php file and not to the config.default.php.

I tried both of your suggestions. But it seems that adding any of these two, will still allow all the other languages to be available in the dropdown.
I am trying to avoid that, in an attempt to reduce the available options to users (also not to have these options in the content translate section).

As for disabling language options: ideally I'd just reduce the number of options so that a user may still choose, but only between French and (British) English.

Mike Perry

unread,
Mar 16, 2021, 10:29:37 AM3/16/21
to ResourceSpace
Oops -- disabling language statement should be:

# Disable language selection options (Includes Browser Detection for language)
$disable_languages=true;

Still playing with reducing available options. . .

jum...@gmail.com

unread,
Mar 17, 2021, 2:12:57 PM3/17/21
to ResourceSpace
Thanks, I tried disabling the options; combined with browser auto detect it's not a bad choice, but I'd still prefer to give users the option to switch between FR and EN.

Mike Perry

unread,
Mar 17, 2021, 2:32:47 PM3/17/21
to ResourceSpace
It's puzzling that deleting the unwanted entries in config.php doesn't change what's displayed in the drop down.

jum...@gmail.com

unread,
Mar 18, 2021, 7:33:08 AM3/18/21
to ResourceSpace
Yes exactly! I guess it could be done in another file, but I'd prefer not to mess with the installation so that future updates are not going to undo the work.

Mike Perry

unread,
Mar 18, 2021, 10:34:33 AM3/18/21
to ResourceSpace
I can't find the language listings in any other file. It's possible config.php is cached by the server or browser and changes aren't immediately reflected in what is displayed, but I doubt it.

jum...@gmail.com

unread,
Mar 18, 2021, 10:49:21 AM3/18/21
to ResourceSpace
I think the changes are immediate, because $disable_languages=true; is reflected in the site rightaway.

There is the languages folder itself; I tried simply deleting a language file there but it remained visible in the dropdown.



Mike Perry

unread,
Mar 18, 2021, 11:18:31 AM3/18/21
to ResourceSpace
Found a solution.

create a custom plugin for config.php. Include ONLY the default language and the language options you want

language.jpg

jum...@gmail.com

unread,
Mar 18, 2021, 11:27:49 AM3/18/21
to ResourceSpace
Great, that seems to work well on your end! Would you be OK to share the code for the plugin? 

Mike Perry

unread,
Mar 18, 2021, 11:49:11 AM3/18/21
to ResourceSpace
Best advice I have is to view the RS Knowledge Base on coding plugins (link) -- it's real easy. This one would be for the config folder and would be in the config.php file in that folder. Just copy the default language and the desired available languages code into it.

It basically creates a secondary custom config.php file. You can also do this for language and css customizations . . .

jum...@gmail.com

unread,
Mar 18, 2021, 11:55:05 AM3/18/21
to ResourceSpace
Thank you, I had a look just now, will give it a try! 

jum...@gmail.com

unread,
Mar 18, 2021, 2:55:52 PM3/18/21
to ResourceSpace
Update: this works perfectly well! Thanks for the suggestions.

Mike Perry

unread,
Mar 18, 2021, 3:04:11 PM3/18/21
to ResourceSpace
👍

ronnie....@gmail.com

unread,
Mar 19, 2021, 5:08:40 AM3/19/21
to ResourceSpace
Hi,

you could write into config.php

$languages = array();     // this makes the array empty
// then you add just this two options
$languages["en-US"]="American English";
$languages["fr"]="Français"; # French



jum...@gmail.com

unread,
Mar 19, 2021, 5:24:22 AM3/19/21
to ResourceSpace
Thank you! I tried the array() solution and it works well for me. 

I learned how to compile a basic plugin in the process, so it's all good :)

Mike Perry

unread,
Mar 19, 2021, 10:52:16 AM3/19/21
to ResourceSpace
Ronnie -- is there somewhere in the RS code that writes the config.php language listing into an array? If so, why wouldn't editing the config.php code alter what gets written??

ronnie....@gmail.com

unread,
Mar 20, 2021, 5:58:16 AM3/20/21
to ResourceSpace
Hi Mike,

many of the config variables are declared as array() in config.default.php
e.g.: $tile_styles['srch']  = array('thmbs', 'multi', 'blank');

with $languages there are just definitions starting with this
$languages["en"]="British English";

which is an implicit declaration.
But you do not know, if $languages is not declared somewhere else in RS code.
(It is not by the way)

Imho a better design to show this would be to write into config.default.php:
$languages = array();
$languages["en"]="British English";
...

ronnie....@gmail.com

unread,
Mar 20, 2021, 6:00:30 AM3/20/21
to ResourceSpace
sorry Mike, I did not answer your question:
if you just write
$languages["en"]="British English";

the array $languages will not be emptied.

Mike Perry

unread,
Mar 20, 2021, 8:02:19 AM3/20/21
to ResourceSpace
Ronnie -- no problem. Thanks for the replies.

A PHP savant I am not <g>. I basically understand your answer. Does each subsequent language declaration in config.default.php add to the array? That would make sense. What's puzzling is the addition of only specific language declarations in config.php does not override the default declaration (config.default.php), but putting selected declarations into the config section of a plugin does.

It's a mystery. . .at least to me!!

Mike

ronnie....@gmail.com

unread,
Mar 20, 2021, 11:02:34 AM3/20/21
to ResourceSpace
Mike - your questions

Does each subsequent language declaration in config.default.php add to the array? 

Yes

What's puzzling is the addition of only specific language declarations in config.php does not override the default declaration (config.default.php), but putting selected declarations into the config section of a plugin does.

I do not think that this happens


Because, if you write into the config.php of a plugin
$languages["en"]="British English"; 

it will be a local variable which doesn't´t change anything globally.

You would have to write
global $languages;
first.

But, even so
$languages["i-do-not-know"]="whatever"; 

would just add a new element to the global $languages Array

But if you write into config section of a plugin
global $languages;
$languages = array();     <<<<  this deletes the Array from config.default.php
$languages["en"]="British English";

a new array with just this one element will be (globally) created.

Mike Perry

unread,
Mar 20, 2021, 11:21:25 AM3/20/21
to ResourceSpace
"I do not think that this happens"

I did it with a plugin --- see the image I posted to the OP. . .

ronnie....@gmail.com

unread,
Mar 20, 2021, 11:46:17 AM3/20/21
to ResourceSpace
strange

I just tried in a plugin...
But I tried the other way around. I checked to see the $languages variables of the config.default.php in the plugin

But you are definitely right!!


It is the other way around!!

Every variable in the config.php of a plugin overrides the one in the config.php to the config.default.php by unset() and creating new one!

# Copy config variables to global scope.
    unset($plugin_name, $config, $config_json, $configpath);
$vars = get_defined_vars();
foreach ($vars as $name=>$value)
{
global $$name;
$$name = $value;
}


Thank you!
Just learned something new.

Mike Perry

unread,
Mar 21, 2021, 9:11:37 AM3/21/21
to ResourceSpace
It's good to now I"m not crazy!!

All said -- your solution is probably more appropriate from a programing perspective. I'm more of a pragmatist than a classical programmer 😊.

I learned something too -- thanks, Coach!!
Reply all
Reply to author
Forward
0 new messages