Customized strings in the new theme

Hi,

I have two journals under one site. I have created a theme for each. I want to change the tab names like “Archives” to “Issues” in one of the journals. I have done these:

I have enabled Custom Locale Plugin.
I have added a locale folder in the newly created theme containing en_US/local.xml
I have defined new values for the keys.
I have also tried reloading en_US.
Also added below function in my new themeplugin.inc.php

function register($category, $path) {
if (parent::register($category, $path)) {
# Add theme specific locale data to the application’s pool
$this->addLocaleData();
return true;
}
return false;
}

The problem is that my new locale.xml file does not appear in manager/plugin/generic/customlocaleplugin/edit/en_US and therefore does not change the string on the website.

Would you please let me know what is missing here?

Regards
Ghazal

Hi @salehig,

You can do what you want using only the custom locale plugin, changing the locale key from the original system locale file. You don’t need to move the locale file into your theme plugin. And even if you do, the system will use the default locale.xml file instead of the one you created for your plugin.

Cheers,
Bruno

Hi Bruno,

Thanks for your reply. My reason to that is that My two journals needs to look different, with different wording of the menu bars. If I update it in generic, they all will be updated.

Regards
Ghazal

@salehig,

Oh, sure. It seems you have PHP skills, so I would suggest you to take a look at this plugin: http://lib-git.lib.sfu.ca/beghelli/customTemplateManager/blob/master/CustomTemplateManagerPlugin.inc.php

What it does is that it changes the template files before the compilation. You can use the same pattern here to search for the locale key string and replace it by the one implemented by your plugin. This process would be done only once, since the compilation only runs when there is no compiled cache.

Take a look at the plugin, how it registers first into the template manager display method and then into the smarty pre compile filter, and how the callback for that pre compile filter works. I think you will understand how you can use this approach to implement a custom locale.

Also, you might want to add your new locale key inside a conditional statement, checking if the plugin is enabled for the journal. If yes, then the locale key should be used, if not, then the default one should be. You need this check inside the template file because OJS shares the compiled files between journals. So if a journal has this enabled, it will add the new locale key into the template file and all the other journals will use it. But journals that don’t have the plugin enabled will give no chance for the plugin itself to “clean up” the template, so that’s why we need the check always there.

It can be a simple variable that you can pass into the plugin’s template manager callback, saying that the plugin is enabled. The conditional statement can check for that variable, if it doesn’t exists, the plugin is not enabled and it will use the default locale key.

I hope this all makes sense, sorry if I throw a lot of things to you at once. Let me know if I can help you more.

Cheers,
Bruno

@beghelli

Thanks heaps for the info. I tried clearing template and data cache. Also found that getLocaleFilename for my journal2 theme used to return null. So I fixed that. Then the corresponding locale.xml appeared in Custom Locale Plugin list and also the strings were updated!!! Success!

Thanks
Ghazal

@salehig,

I am not sure how you managed to overwrite a system default locale key definition by placing the same key definition inside a theme template file. But it seems you have what you need. Can you further explain what you did, I am curious. :smile:

Thanks,
Bruno

@beghelli

I am maintaining this system and not 100% aware of its details. However my understanding is that overwriting system locale messages is possible by adding a new theme directory in plugin/theme, containing below items:

index.php
journal2.css
journal2ThemePlugin.inc.php
locale/en_US/locale.xml

Everything is similar to a normal theme. The only thing is that function getLocaleFilename($locale) in journal2ThemePlugin.inc.php shouldn’t be overridden.

We can define our customized messages in plugin/theme/journal2/locale/en_US/locale.xml with the same format the system’s locale file.

Cheers
Ghazal