Joomla RTL support for module - joomla

I am trying to support RTL for my Joomla module. I was wondering if there is any Joomla class that can determine if RTL language is currently in use such as:
$lang = JFactory::getLanguage();
if ($lang->isRTL()) {
//do something here
}
I have tested the code above which I found in the Official Joomla Forums, but it does not seem to work.
In the Beez20 template I saw the following code:
if ($this->direction == 'rtl') {
}
but assumed this a template based statement.
So my question is, is there any way I can detect if the language that the website is being viewed in is an RTL language?

The first code snippet used in my answer works as shown below as well:
$lang = JFactory::getLanguage();
if ($lang->isRTL()) {
//do something here
}
Only reason being it didn't work, was because I had another 2 if statements that were the wrong way round to this one.

Related

Joomla Language Filter Plugin & Changing a language field in the front end

I try to get the Releasemaker from Akeeba running and set the language for a release/item to All (*). But one can assume that this kind of problem should happen to any kind of code which tries to set a database field language using code in the Site folder.
If you have a multilingual site you probably have the plugin "System - Language Filter" running. This plugin sets a $_REQUEST['language'] value to a specific language. Every time. As a result code like $data = $app->input->getData() will get the language value of that $_REQUEST value instead of the value from the $_POST array so you can't set that language field with the usual ->bind($data) operation.
Did you encountered that issue as well? What is your solution for this?
I got myself a solution for this. I actually can imaging two ways to solve this. On the one hand you can rename the language parameter which is transferred from the client to the server and do magic stuff in the persistent layer. On the other hand you can try to fix the work of the language filter plugin. Since I don't want to change the component I chose the second way and added a system plugin to reset the language value in the request to * as I need it. Of course one can read that value from the POST data as well. The plugin is as strict as possible where to do that magic to not crash the other stuff.
class PlgSystemLanguagefixer extends JPlugin
{
public function onAfterRoute() {
// Get the application object.
$app = JFactory::getApplication();
$option = $app->input->get('option');
$format = $app->input->get('format');
$task = $app->input->get('task');
$view = $app->input->get('view');
if ($option == 'com_ars' && $task=='save' && $format == 'json' && ($view=='releases' || $view='items')) {
$app->input->set('language', '*');
}
}
}
Please note that this question is still open for better answers :)

Joomla - call function model within the model

In a public function of my model I call
$user_type=$this->get_user_type();
In the same model I have
private function get_user_type()
{
$user_type='asd';
$asd_groups = (int)$config->get('asd_groups');
$ver_groups = (int)$config->get('ver_groups');
jimport( 'joomla.user.helper' );
$user_groups=JUserHelper::getUserGroups($user->id);
if(in_array($asd_groups,$user_groups)){
$user_type='asd';
}
if(in_array($ver_groups,$user_groups)){
$user_type='ver';
}
return $user_type;
}
The site give me a white page, if I comment the calling line "$this->get_user_type();" then it works...
I really don't understand what is wrong here.
There is not enough information or code here to help you… for example where is $config coming from and what is it? What version of Joomla is this on?
If $config is not defined as a global then that may be the source of the problem depending on your PHP setup.
Things you can do to help yourself find the problem, in Joomla's Global Configuration.
Set Error Messages to "Development" in Joomla (you are using a development site and not a live website right?)
Turn on Joomla's DEBUG mode
Then update your question with details of error messages, Joomla version and where this code is running (you say your model) and where $config is coming from.
Oh sure!
I have missed the two configuration variable when i moved the code from inside a function in a dedicated function.
I copied these two lines on the first row of the function and now it works!
$config = JComponentHelper::getParams(S_APP_NAME);
$user = JFactory::getUser ();

How to implement multiple languages without abusing the Template system?

I converted our Meteor site to support two languages, Dutch and English. To do this I made two folders for our templates (en and nl) and hooked everything up to our templating system so the router serves things correctly depending on which site you're on. The main body template is dynamic:
Template.body.content = function() {
var lang = Session.get("lang") == "en" ? "en_" : "";
var page = Session.get("page") || "home";
// if the template for the current language doesn't exist,
// fall back to Dutch version or show a 404
var template = Template[lang + page] || Template[page] || Template[lang + "error404"];
return template();
}
Everything works pretty well except that I have to write the following to expose a template value to both languages:
Template.en_foo.bar = Template.foo.bar = function() {}
For an example of this code as used in production, see our client-side blog code.
What's an elegant way to avoid this approach while still accomplishing the goal of a multilingual site?
What about this:
make a custom subscription and pass the language argument to a custom publish
the custom publish function returns only the selected language (optionally you can provide fallbacks if content is unavailable)
use just one template for all languages, filled with the right language from the subscription
use i18n package for the UI strings
Multi-languages applications is on the Meteor roadmap but it's planned in a long time...
Meanwhile you can use this atmosphere package.
I'd recommend heavily against keeping translated versions of your templates around. Unless your site is tiny. It might not seem so bad at first because you just copy them and translate the contents. But from then on you'll have to maintain both versions on any change, test both. And then somebody will suggest adding that third language and boom, triple damage to your brain.
We're using meteor-messageformat for translations. It comes with an interface that allows creating translations without having to look at template code. Anybody can translate.

how does magento URL access work

Hi i wanted to create a custom form to get input from the user, i can access the form from the url :
http://localhost/website/index.php/contest
but when i uploaded it to a server which has multiple website setup in the magento, i could not access the form like i used to on local server.
http://www.website.org/index.php/contest
i am stumped , i hit a wall i googled, i just don't know what to look for , any help will be greatly appreciated. Thanking anyone in advance
Magento routing is a sort of big topic to cover in a single Stack Overflow answer. You can read about the basics of setting up a controller here, and the probably in too much depth routing process here.
That said, here's some general debugging tips.
Can Magento see the module your controller is a part of? If not, you're probably missing your file in app/etc/modules. (look at the module list in `System -> Configuration -> Advanced -> Disable Module Output)
If your module is installed, Magento probably can't find your controller class. Eitehr because it's not there, of you have a case sensitivity issue. Add some temporary debugging code to the _validateControllerClassName function to determine why Magento can't find your controller.
You can find the _validateControllerClassName function here
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
return false;
}
return $controllerClassName;
}
Some var_dumps before the return false clauses should tell you why Magento can't find and/or include your controller class file.

How to add links that select the preferred language (CodeIgniter's Language Class)?

I just finished this tutorial:
http://codeigniter.com/wiki/Internationalization_and_the_Template_Parser_Class/
but now I want some links to change english to spanish
I know how to change it by modifying the controller example.php:
# Load language
$this->lang->load('example', 'english');
But I can't figure out how to do that in the view file example.php
What's the simplest and best way of doing this?
You should be able to do something like this:
function set_lang($lang)
{
return $this->config->set_item('language', $lang);
}
You should also add the 'language' library to the autoload config and then just put the $this->lang->line() to the appropriate places.

Resources