Skip to content

Commit

Permalink
Merge pull request #233 from robbieaverill/feature/non-default-locale…
Browse files Browse the repository at this point in the history
…-indicator

Add visual UI indicator for whether you are editing in the default locale or not
  • Loading branch information
Damian Mooyman authored Oct 11, 2016
2 parents b4ce332 + fd6c468 commit e084a41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
36 changes: 33 additions & 3 deletions code/extensions/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,9 @@ protected function localiseFilterCondition($condition, $includedTables, $locale)
protected function localiseSelect($class, $select, $fallback)
{
return "CASE COALESCE(CAST(\"{$class}\".\"{$select}\" AS CHAR), '')
WHEN '' THEN \"{$class}\".\"{$fallback}\"
WHEN '0' THEN \"{$class}\".\"{$fallback}\"
ELSE \"{$class}\".\"{$select}\" END";
WHEN '' THEN \"{$class}\".\"{$fallback}\"
WHEN '0' THEN \"{$class}\".\"{$fallback}\"
ELSE \"{$class}\".\"{$select}\" END";
}

public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
Expand Down Expand Up @@ -813,6 +813,36 @@ public function updateCMSFields(FieldList $fields)
}
}
}

$this->addLocaleIndicatorMessage($fields);
}

/**
* Adds a UI message to indicate whether you're editing in the default locale or not
*
* @param FieldList $fields
* @return self
*/
protected function addLocaleIndicatorMessage(FieldList $fields)
{
$localeNames = Fluent::locale_names();
$isDefaultLocale = (Fluent::default_locale() === Fluent::current_locale());
$messageClass = ($isDefaultLocale) ? 'good' : 'notice';
$message = ($isDefaultLocale)
? _t('Fluent.DefaultLocale', 'This is the default locale')
: _t('Fluent.DefaultLocaleIs', 'The default locale is') . ' ' . $localeNames[Fluent::default_locale()];

$fields->unshift(
LiteralField::create(
'CurrentLocaleMessage',
sprintf(
'<p class="message %s">' . _t('Fluent.EditingIn', 'Please note: You are editing in') . ' %s. %s.</p>',
$messageClass,
$localeNames[Fluent::current_locale()],
$message
)
)
);
}

// </editor-fold>
Expand Down
3 changes: 3 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ en:
LocaleFilterDescription: 'Check a locale to show this item on that locale'
LocaleMenuFilterDescription: 'Select the locales where this item is visible in the menu'
TABLOCALES: Locales
DefaultLocale: 'This is the default locale'
DefaultLocaleIs: 'The default locale is'
EditingIn: 'Please note: You are editing in'

0 comments on commit e084a41

Please sign in to comment.