Skip to content

Commit

Permalink
[Optimize] Add "Force translate default language" option
Browse files Browse the repository at this point in the history
  • Loading branch information
Thong Tran committed Jan 19, 2017
1 parent 704bf00 commit 3e204e3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions extensions/components/com_redcore/admin/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="force_translate_default_site_language"
class="btn-group"
type="radio"
default="0"
label="COM_REDCORE_CONFIG_TRANSLATIONS_FORCE_TRANSLATE_DEFAULT_SITE_LANGUAGE"
description="COM_REDCORE_CONFIG_TRANSLATIONS_FORCE_TRANSLATE_DEFAULT_SITE_LANGUAGE_DESC">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>
<fieldset name="REDCORE_WEBSERVICES_OPTIONS"
addfieldpath="/libraries/redcore/form/fields"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ COM_REDCORE_CONFIG_TRANSLATIONS_CONSTRAINT_TYPE_DESC="Constraint between origina
COM_REDCORE_CONFIG_TRANSLATIONS_CONSTRAINT_TYPE_FOREIGN_KEYS="Foreign Keys (InnoDB)"
COM_REDCORE_CONFIG_TRANSLATIONS_CONSTRAINT_TYPE_TRIGGERS="Triggers"
COM_REDCORE_CONFIG_TRANSLATIONS_CONSTRAINT_TYPE_NONE="None"
COM_REDCORE_CONFIG_TRANSLATIONS_FORCE_TRANSLATE_DEFAULT_SITE_LANGUAGE="Force translate default language"
COM_REDCORE_CONFIG_TRANSLATIONS_FORCE_TRANSLATE_DEFAULT_SITE_LANGUAGE_DESC="When enabled. System will also translate even default language or not"

; Webservices
COM_REDCORE_CONFIG_WEBSERVICES_OPTIONS="Webservice options"
Expand Down
5 changes: 5 additions & 0 deletions extensions/libraries/redcore/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ class_alias('JRegistry', 'Joomla\Registry\Registry');
// Setting default option for translation fallback
RDatabaseSqlparserSqltranslation::setTranslationFallback(self::getConfig('enable_translation_fallback', '1') == '1');

// Setting default option for force translate default language
RDatabaseSqlparserSqltranslation::setForceTranslateDefaultLanguage(
self::getConfig('force_translate_default_site_language', '1') == '1'
);

// Reset plugin translations params if needed
RTranslationHelper::resetPluginTranslation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public static function parseSelectQuery($sql = '', $prefix = '', $language = 'en
public static function buildTranslationQuery($sql = '', $prefix = '')
{
$db = JFactory::getDbo();

$selectedLanguage = !empty($db->forceLanguageTranslation) ? $db->forceLanguageTranslation : JFactory::getLanguage()->getTag();

if (!empty($db->parseTablesBefore))
Expand All @@ -195,7 +196,7 @@ public static function buildTranslationQuery($sql = '', $prefix = '')
$validSelect = (!empty($sql) && stristr(mb_strtolower($sql), 'select'));

// If the language is the default, there is no reason to translate
$isDefaultLanguage = (RTranslationHelper::getSiteLanguage() == $selectedLanguage);
$isDefaultLanguage = (RTranslationHelper::getSiteLanguage() == $selectedLanguage) && !self::getOption('forceTranslateDefault', false);

// If this is the admin, but no an API request we shouldn't translate
$isAdmin = RTranslationHelper::isAdmin();
Expand Down Expand Up @@ -1058,4 +1059,16 @@ public static function setTranslationFallback($enable = true)
{
self::setOption('translationFallback', $enable);
}

/**
* Set a translation option force translate default value.
*
* @param bool $enable Enable or disable force translate default language feature
*
* @return null
*/
public static function setForceTranslateDefaultLanguage($enable = false)
{
self::setOption('forceTranslateDefault', $enable);
}
}

0 comments on commit 3e204e3

Please sign in to comment.