Mark, I’ve run into a wall. I have custom fields for each weblog, and I’ve adopted a naming scheme of {WEBLOGNAME-body} for my custom fields, since EE requires a unique short name for custom fields, regardless of them being in different field groups. The problem is when I want to have alternate languages for the {title} field. Normally I’d have custom fields named {title_jp} and be done with it, but since I have to have them named uniquely, and I want to have more than one weblog have alternate language content, Simple Translator obviously doesn’t pick up on the fact that {WEBLOGNAME-title_jp} should be substituted for the {title} field when the language is changed. The only solution I can think of is to have an “if lang == jp show {WEBLOGNAME-title_jp} else show {title}” conditional in my templates, but it seems rather messy. Any ideas?
Yes. I also have this problem. I need to be able to translate the title of each entry and you can’t have more than one title_{LANG} custom field. Appending a WEBLOGNAME to each custom field will work for everything except title.
Any suggestions?
Matt @ View Creative
one more question: is there a way to exclude the current language from the link list? To me there is no need to show a link to switch to english if the page is already in english.
You can use something like this:
{if simple_language == "Spanish"}<a href="http://index.php/lang/default/">English</a>
{if:else}<a href="http://index.php/lang/_es/">Español</a>{/if}
My path looks weird but it actually worked for me.
Love this extension! Just wanted to change one thing: instead of an unordered list, I wanted a dropdown menu. I made a little hack to my copy which seems to do the trick. Don’t like messing with mods, but thought this might be useful for some. Hope that’s okay Mark!
Paste the following over lines 189-374 of ext.simple_translator.php.
<pre><code>$r = ‘<form action=”” name=”langmenu” method=”post”><select name=”langsel”><option selected value=”“>Change language…</option>’;
// =============================================
// Error Prevention
// =============================================
// We want to make sure that there is always
// a languages element of the settings array
// ---------------------------------------------
if(!isset($this->settings['languages']))
{
$this->settings['languages'] = '';
}
// =============================================
// Find the HREF
// =============================================
// We'll parse out the base href, because I
// don't know of any better way to do this.
// ---------------------------------------------
$base = preg_replace('/\/$/', '', $PREFS->core_ini['site_url']).'/';
if($PREFS->core_ini['site_index'] != '') $base.= $PREFS->core_ini['site_index'];
if($PREFS->core_ini['force_query_string'] == 'y') $base.= '?';
$base = preg_replace('/\/$/', '', $base).'/';
// =============================================
// Add SEGS to the HREF
// =============================================
// We'll add all the segs up to, but not
// including the language segments
// ---------------------------------------------
$segs = array();
foreach($IN->SEGS as $k=>$s)
{
if($s == 'lang' && $k == count($IN->SEGS)-1) break;
$segs[] = $s;
}
$base.= implode('/', $segs);
$base.= (count($segs) > 0)?'/':'';
// =============================================
// Set Cookie
// =============================================
// If we are looking at a new language from the
// url we'll set the new cookie and redirect to
// the lang'less url
// ---------------------------------------------
if(@$IN->SEGS[count($IN->SEGS)-1] == 'lang')
{
$value = $IN->SEGS[count($IN->SEGS)];
if($value == 'default') $value = false;
$FNS->set_cookie($this->cookie_name, $value, 60*60*24*7);
header('Location: '.$base);
exit;
}
// =============================================
// Get Category Groups, Weblogs & Vars
// =============================================
// We'll get these so we can switch them too!
// ---------------------------------------------
if(!is_array($sess->cache)) $sess->cache = array();
if(!isset($sess->cache['mh_table_category_groups']))
{
$sess->cache['mh_table_category_groups'] = array();
$cat_groups_q = $DB->query('SELECT * FROM exp_category_groups');
foreach($cat_groups_q->result as $group)
{
$sess->cache['mh_table_category_groups'][$group['group_name']] = $group;
}
}
if(!isset($sess->cache['mh_table_weblogs']))
{
$sess->cache['mh_table_weblogs'] = array();
$weblogs_q = $DB->query('SELECT * FROM exp_weblogs');
foreach($weblogs_q->result as $weblog)
{
$sess->cache['mh_table_weblogs'][$weblog['blog_name']] = $weblog;
}
}
if(!isset($sess->cache['mh_table_global_variables']))
{
$sess->cache['mh_table_global_variables'] = array();
$vars_q = $DB->query('SELECT * FROM exp_global_variables WHERE user_blog_id="'.((!defined('UB_BLOG_ID'))?0:UB_BLOG_ID).'"');
foreach($vars_q->result as $var)
{
$sess->cache['mh_table_global_variables'][$var['variable_name']] = $var['variable_data'];
}
}
// =============================================
// Get the List
// =============================================
// We'll parse through our available languages
// and create a list.
// We'll also set our category and weblog
// switches here.
// ---------------------------------------------
$languages = array_filter(preg_split('/[\r\n]+/', $this->settings['languages']));
foreach($languages as $k=>$l)
{
$tmp = array_filter(preg_split('/:/', $l));
if($k == 0)
{
$tmp[0] = 'default';
$tmp[1] = $l;
}
if(count($tmp) == 1)
{
$tmp[1] = $tmp[0];
}
// =============================================
// Check Selected Language
// =============================================
// Here we'll class the selected language in the
// list and then set up other translations.
// ---------------------------------------------
$class = array();
if((isset($_COOKIE[$this->c_cookie_name]) && $_COOKIE[$this->c_cookie_name] == $tmp[0]) || (!isset($_COOKIE[$this->c_cookie_name]) && $tmp[0] == 'default'))
{
$class[] = 'selected';
$IN->global_vars['simple_lan
pls. allow a few questions for mark huot:
2. will changing the url_title work and how does google cope with the double language content?
will this extension hold in ee 2.0?
which is - in your experience - the best ee multi-lang approach?
thank you!
Nice, I’d drop the PHP code and use this instead:{if simple_language == "English"} <a href="http://{path=">Nederlands</a> {if:else} <a href="http://{path=">English</a> {/if}
Hey Cocoaholic,
How is this working for you?? I try using your method on an embedded template but only works on the home/index page. Lets say I’m on the “About” page and I use this… it takes me back to the home page.
This code actually worked for me on every page:
{if simple_language == "Spanish"}
<a href="http://index.php/lang/default/">English</a>
{if:else}
<a href="http://index.php/lang/_es/">Español</a>
{/if}
The problem with this is that it generates an extra index.php every time the language gets switched. Like this:
http://mysite.com/index.php/about/index.php/index.php/index.php/
It does the job since it takes me to the right page in the right language but that doesn’t look right.
Is there another variable other than {path="site_index"} than could be used so it recognized the location where the switcher is used? or do you have any ideas why your method isn’t working for me?
Thanks
I am a little lost here, because I am trying to translate the “blog” section of my website, so basically I created a similar category group adding “fr extension to it, and then creating similar custom fields, but in french. (so I have 2 category groups the english one “3” the french “4”)
now i wanted the english to be default and then change it to french, so I add: category_group=”{exp:translator:simple category_group="3"}” to my categories tags, when I switch languages I everything changes, except the categories…Is there is something I am missing here,I will be very glad if you take your time to answer me.
this is my actual code.
{exp:weblog:category_heading weblog="{my_weblog}” category_group=”{exp:translator:simple category_group="3"}”} <h3 class=”company_titles”>{category_name}</h3> {if category_description} {category_description} {/if}
{/exp:weblog:category_heading}
I ve added {exp:transl…} as specified in the information that comes with the extension.
I will like to translate the category title and content, but I am not sure where to add the “simple translator” code on this. I created 2 categories groups weblog and weblog_fr so I will like to be able to switch between both, THANKS for any help on this!
I am a little lost here, because I am trying to translate the “blog” section of my website, so basically I created a similar category group adding “_fr_ extension to it, and then creating similar custom fields, but in french. (so I have 2 category groups the english one “3” the french “4”) now i wanted the english to be default and then change it to french, so I add: category_group=”{exp:translator:simple category_group="3"}” to my categories tags, when I switch languages I everything changes, except the categories…Is there is something I am missing here,I will be very glad if you take your time to answer me. this is my actual code. {exp:weblog:category_heading weblog="{my_weblog}” category_group=”{exp:translator:simple category_group="3"}”} <h3 class=”company_titles”>{category_name}</h3> {if category_description} {category_description} {/if} {/exp:weblog:category_heading} I ve added {exp:transl…} as specified in the information that comes with the extension. I will like to translate the category title and content, but I am not sure where to add the “simple translator” code on this. I created 2 categories groups weblog and weblog_fr so I will like to be able to switch between both, THANKS for any help on this!
I found the answer searching on this post, actually I was missing to assign several categories to the same weblog…oops
I have a small question though…something not really that important but well…
Is there a way to use the Simple Translator plugin to translate:
{exp:weblog:month_links weblog="{embed:the_weblog}”} <dd><a href=”http://{path=">{month}, {year}</dd> {/exp:weblog:month_links}
I thought of creating a weblog…and assign 3 custom fields (english/french/spanish) as I am doing with the other content, thing is that the months are generated dynamically with that tag, so I am not sure what approach to take.
Like I say this might sound insignificant…but just wondering, thanks…
Any progress adding category custom fields? I think this existing plugin with that one last feature added will finally be the last piece in the multi-language puzzle.
I’m just playing with this extension for the first time today, so pardon any ignorance…
I know this is probably not the best way to do this. Please help if there’s a more elegant way.
{exp:weblog:entries weblog="my_weblog" }
{categories}
{Subjects{simple_language}}
{/categories}
{/exp:weblog:entries}
Then I have my category custom fields titled “SubejctsEnglish”, “SubjectsFrench” and so on. I’d rather append a ‘_en’ suffix to the end of the name, but not sure what tag that would be.
Also, there’s the thing where if you don’t have a custom field for the language, you just get the tag. Might need an {if simple_language} . I’ll take a look at it again in the morning.
This is a great extension Mark - thanks. Any thoughts on how Google will like this solution vs. the method outlined here?
alright textdriven, 1.0.9 should switch global variables now. it works the same as always, use {branding} for your default language, and {branding_ja} for japanese specific content. as for embeds, it is a little trickier as I don’t have access to the template through an extension. You could however do this with a conditional:{if simple_language == "English"} ... {if:elseif simple_language == "German"} ... {/if}
Hi there,
I got simple translator working fine, I wanted to display just one “language name” at the time, but didn’t seem to get it working, I currently have just:
<tr> <td>
{exp:translator:simple}
</td> </tr>
but displays both languages.
I tried using
<tr> <td>
{if simple_language == "English"} english {if:else} french {/if}
</td> </tr>
but didn’t seem to work, might be missing somthing, please I will appreciate your feedback on this, I am quite new to php so might be doing something wrong thanks.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.