HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[How To] Tutorial: Theme specific definitions (mobile vs. non-mobile)

peregrineperegrine MVP
edited December 2013 in Tutorials

If you want different wording or date time formats for your theme when viewing on mobile vs. normal viewing,

configure and enable your locale in dashboard.

e.g. is based on using country code en-US (your country or locale may differ).

determine your locale from your config.php
e.g. 
// EnabledLocales
$Configuration['EnabledLocales']['en-US'] = 'en-US';

// the default locale.
$Configuration['Garden']['Locale'] = 'en-US';

if your theme is called MyTheme

create themes/MyTheme/locale/en-US.php

in en-US.php



<?php if (!defined('APPLICATION')) exit();


 $IsMobile = (IsMobile());

 if ($IsMobile) {
//  your mobile specific definitions - change the right hand side of equations.

$Definition['Discussions'] = 'Posts';
$Definition['Date.DefaultDayFormat'] =  'mobile theme %B %e';
$Definition['Date.DefaultFormat'] = 'mobile theme %B %e, %Y';
$Definition['Date.DefaultTimeFormat'] =  'mobile theme %l:%M%p';
$Definition['Date.DefaultYearFormat'] = 'mobile theme %B %e, %Y';

}   else {
  //  your NON-mobile specific definitions - change the right hand side of equations.
$Definition['Discussions'] = 'Discussions';
$Definition['Date.DefaultDayFormat'] =  'not mobile theme %B %e';
$Definition['Date.DefaultFormat'] = 'not mobile theme %B %e, %Y';
$Definition['Date.DefaultTimeFormat'] =  'not mobile theme %l:%M%p';
$Definition['Date.DefaultYearFormat'] = 'not mobile theme %B %e, %Y';


}

you could also use the same technique in conf/locale.php or other definition files.

keep in mind if you define the same $Definition['thedefinition'] in multiple files or multiple time in the same file. The last instance will be used.

the order or sequence of definitions is
1 - application based and dashboard based definitions
2- plugin based - plugins/SphinxSearch/locale/en-US.php"
plugins/SphinxSearch/locale/en-US/definitions.php
3 - theme based /themes/YOURTHEMENAME/locale/en-US.php
4 - locale based - /locales/en-US/definitions.php"
5 - locale based /vanilla/locales/en-US/other_definitions.php"
6- conf based /vanilla/conf/locale.php"
7- conf - specialized /conf/locale-en-US.php"

it will be overruled by the highest number.


so if

$Definition['Discussions'] = 'Discussions'; //is in /themes/YOURTHEMENAME/locale/en-US.php

and

$Definition['Discussions'] = 'My Discussions' ;is in conf/locale.php

the definition in conf/locale.php will take precedence because it has a higher number.

When changing locales, adding locale files, deleting locale files,

  • always delete /cache/locale_map.ini

to get changes to take effect

also see: http://vanillaforums.org/docs/localization

you could also do the same thing in conf/locale.php for all apps and themes.
this file will override all definition files except the specialized country specific files in conf folder /conf/locale-en-US.php),

create conf/locale.php

in locale.php



<?php if (!defined('APPLICATION')) exit();


 $IsMobile = (IsMobile());

 if ($IsMobile) {
//  your mobile specific definitions - change the right hand side of equations.

$Definition['Discussions'] = 'Posts';
$Definition['Date.DefaultDayFormat'] =  'mobile theme %B %e';
$Definition['Date.DefaultFormat'] = 'mobile theme %B %e, %Y';
$Definition['Date.DefaultTimeFormat'] =  'mobile theme %l:%M%p';
$Definition['Date.DefaultYearFormat'] = 'mobile theme %B %e, %Y';

}   else {
  //  your NON-mobile specific definitions - change the right hand side of equations.
$Definition['Discussions'] = 'Discussions';
$Definition['Date.DefaultDayFormat'] =  'not mobile theme %B %e';
$Definition['Date.DefaultFormat'] = 'not mobile theme %B %e, %Y';
$Definition['Date.DefaultTimeFormat'] =  'not mobile theme %l:%M%p';
$Definition['Date.DefaultYearFormat'] = 'not mobile theme %B %e, %Y';


}

I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.