1

I have created multilanguage site in Joomla. Default language is English, second language is French.

I created user login module and front end article submission for English website.

I registered a user in English site (front end) and logged in. I clicked on 'Submit an article'.

In 'Create article' page, language is displayed as 'All'. I want this to be displayed as 'English' as the user logged into English website.

If the user is logged into French website, Language should be automatically set to French.

Instead of selecting the language manually, I want to set it automatically to the language the user logged in. Because most of the time, user forgets to select the language.

I believe small piece of code will do this. Can someone please help me to achieve this?

Regards, Ramesh.

1

You can create a view override to modify how the language field is generated.

The current form view (components/com_content/views/form/tmpl/edit.php) has this field generation, line 147:

<div class="tab-pane" id="language">
    <?php echo $this->form->renderField('language'); ?>
</div>

Thus, you can modify the Html generation according to JFactory::getLanguage()->getTag().

|improve this answer|||||
0

You can create the two links in frontend one for English another one for French.

<ul class="lang-inline"><br>
<li dir="ltr" class=""><br>
<a href="/fr/">French</a><br>
</li><br>
<li dir="ltr" class="lang-active"><br>
<a href="http://sitepath/en/"><br>
English</a><br>
</li>
</ul>
|improve this answer|||||
0

I am not sure we can do this without overriding core files. Following is the method which I am using:

P.S. This is not the recommended way as the core files will get overwritten when you update Joomla and you need to redo the changes.

Edit administrator/components/com_content/models/article.php and find below function:

protected function loadFormData()

And inside below if condition

if (empty($data))

Add below code

$data->set('language', JFactory::getLanguage()->getTag());
|improve this answer|||||
0

Infograf answered this question.

As per his comments, I placed the following code in:

/components/com_content/views/form/view.html.php'

after the line: $this->form->setFieldAttribute('catid', 'readonly', 'true'); }

// Propose current language as default when creating new article
if (JLanguageMultilang::isEnabled() && empty($this->item->id))
{
$lang = JFactory::getLanguage()->getTag();
$this->form->setFieldAttribute('language', 'default', $lang);
}

Now it is working as expected.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.