We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Simple Translator (formerly known as Another Language Switcher)

Development and Programming

Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Oh, you’re one step ahead of me bcartier. Good idea, and hopefully that will make it’s way into the next revision.

       
Brent Cartier's avatar
Brent Cartier
87 posts
18 years ago
Brent Cartier's avatar Brent Cartier

Hi Mark,

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 starting a new project soon and I’ll need to decide which approach to use…

No rush though… 😊

Thanks a million!

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

I’ve basically got Simple Translator working, great stuff. However, I need to add an id attribute to each list item (for styling purposes).

Example:

<ul class="simple-translator">
<li id="English" class="selected first"><a href="http://" title="English">English</a></li>
<li id="German"><a href="http://" title="German">German</a></li>
<li id="Dutch"><a href="http://" title="Dutch">Dutch</a></li>
<li id="French"><a href="http://" title="French">French</a></li>
<li id="Italian" class="last"><a href="http://" title="Italian">Italian</a></li>
</ul>

I’d be happy with a class attribute instead, of course.

How can I adapt the extension to add these attributes automatically? I’ve had a look in the extension file itself but don’t see any reference to an unordered list at all.

Thanks!

       
Brent Cartier's avatar
Brent Cartier
87 posts
about 18 years ago
Brent Cartier's avatar Brent Cartier

Hi lithiumdave,

You could always create the list in you templates like so:

<ul class="simple-translator">
   
     <li id="English" {if simple_language == "English"}class="selected first"{/if}>
        <a href="/lang/default/" title="English">English</a>
     </li>

   
      <li id="French" {if simple_language == "French"}class="selected first"{/if}>
          <a href="/lang/_fr/" title="French">French</a>
      </li>

       etc...
</ul>
       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

Now that works really well! Almost…

The only bit I’m struggling with now is the path. For example, a href=”/lang/_de/” finds the root of the site, so I get a 404. The path needs to basically append /lang/_de/ (I think!) to the end of whatever the URL happens to be, in the way that the extension does.

Is there a way of achieving this with a hard-coded path, as in your example?

Many thanks for your help so far 😊

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

I’ve done it like this anyway:

<?php
  $domain = $_SERVER['HTTP_HOST'];
  $url2 = "http://" . $domain . $_SERVER['REQUEST_URI'];
?>

<ul class="simple-translator">
     <li id="English" {if simple_language == "English"}class="selected first"{/if}>
        <a href="http://<?php" title="English">English</a>
     </li>
      <li id="German" {if simple_language == "German"}class="selected"{/if}>
          <a href="http://<?php" title="German">German</a>
      </li>
     <li id="Dutch" {if simple_language == "Dutch"}class="selected"{/if}>
          <a href="http://<?php" title="Dutch">Dutch</a>
      </li>
     <li id="French" {if simple_language == "French"}class="selected"{/if}>
          <a href="http://<?php" title="French">French</a>
      </li>
     <li id="Italian" {if simple_language == "Italian"}class="selected"{/if}>
          <a href="http://<?php" title="Italian">Italian</a>
      </li>
</ul>

It seems to be working ok so far at least. Be interested to learn if there’s a non-PHP way to tackle it.

Cheers.

       
Brent Cartier's avatar
Brent Cartier
87 posts
about 18 years ago
Brent Cartier's avatar Brent Cartier

Sorry lithiumdave, I put in a leading slash by mistake! the links should be a href=”lang/_fr/” (relative) instead of “/lang/_fr” (absolute). That way it adds it to the end of the current url without having to do all the php business.

Let me know if that works for you.

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

What on earth am I playing at?! I can’t believe I actually started messing about with PHP there, so obvious! In my defence, it was the end of a very, very long day (week, actually).

I’ve brought shame on myself and my family…. ; )

Heh heh. Thanks bcartier!

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

As I thought, I’m here again…

The client has now decided that they want category names to also language switch too, even though they insisted they wouldn’t need that when I began.

I’m struggling with implementing category language switching and would appreciate some help, rather urgently in fact!

I have the following code in my templates to output the list of categories, as well as also display the list of entries within each category. Further, there are conditionals in there too to conditionally display entries only if you’re actually viewing that category.

I’ll simplify it next, but just wanted to show what I’ve actually got in there first:

<ul class="sidenav">
{exp:weblog:categories weblog="products" style="linear"} 
                <li {if "{segment_2}" == "C{category_id}" OR "{segment_3}" == "{category_id}"}class="subcurrent"{/if}><a href="http://{path=products}">{category_name}</a>
{if "{segment_2}" == "C{category_id}" OR "{segment_3}" == "{embed:cat}"}
<ul>
{exp:weblog:entries weblog="products" category="{category_id}" dynamic="off"}
{if "{embed:current}" != "{url_title}"}<li><a href="http://{homepage}products/{url_title}/{category_id}/">{title}</a></li>{/if}
{if "{embed:current}" == "{url_title}"}<li><span>{title}</span>{/if}
{/exp:weblog:entries}
</ul>
{/if}
</li> 
{/exp:weblog:categories}
            </ul>

I suppose broken down to brass tacks it’s simply this:

{exp:weblog:categories weblog="products" style="linear"} 
                <li><a href="http://{path=products}">{category_name}</a>
<ul>
{exp:weblog:entries weblog="products" category="{category_id}" dynamic="off"}
<li><a href="http://{homepage}products/{url_title}">{title}</a></li>
{/exp:weblog:entries}
</ul>
</li>
{/exp:weblog:categories}

Now, following Mark’s instructions I’ve done the following to the above:

{exp:weblog:categories weblog="products" style="linear" 
category_group="{exp:translator:simple category_group="2"}"}

as the category group is 2. The category name is ‘Products’.

I’ve now created a new category group called ‘Products_fr’ (which has a group id of 3). However, when I switch languages (to French, using a _fr suffix) no categories whatsoever are output to the page.

I think I might be able to see why, but I just cannot figure out the solution.

Any help very very much appreciated : )

Dave

       
Mark Huot's avatar
Mark Huot
587 posts
about 18 years ago
Mark Huot's avatar Mark Huot

lithiumdave – is there any way you can place an {exp:weblog:entries /} tag onto the page and make sure that normal custom fields are switching? Thanks. Also, can you turn on template debugging and try to find the call to the weblog:categories method? Are there any attributes associated with it? If possible can you PM me a txt file of your template debugger?

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

Thanks for the quick reply Mark, really appreciate it.

I can confirm that normal custom fields are switching no problem, I have it set up here:

http://hotbox.bluestormtests.co.uk and http://hotbox.bluestormtests.co.uk/products/hotbox-heater/4/ are perfect working examples.

You can see the category switching not working on this page:

http://hotbox.bluestormtests.co.uk/products/hotbox-heater/4/ (click the 2nd from right flag, French, at the top of the page - I only have a French category group set up so far, Products_fr)

I’ll PM you the debugging output from that template, and also login details to the CP.

Thank you SO MUCH for your help Mark, you’re a legend.

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

Hi Mark,

I’ve PM’d you but my PM sent messages folder is reporting being empty, which is odd. Anyway, just to let u know I’ve sent the PM. Let me know if u got it 😊

       
Mark Huot's avatar
Mark Huot
587 posts
about 18 years ago
Mark Huot's avatar Mark Huot

lithiumdave – I just looked over your debugging and it seems that the category is switching, from 2 to 3. Can you try hardcoding 3 as a category? Does it work then?

       
lithiumdave's avatar
lithiumdave
215 posts
about 18 years ago
lithiumdave's avatar lithiumdave

It’s odd - I’ve put category_group=”2” and categories get output just fine. Any other number - no joy. I’ve tried category_group=”3” but…

Ah, wait… I need to assign my new language-based category groups to the Products weblog in Admin too don’t I? Doh!

Right… once I do that then the correct categories do display!

However, the category links are now incorrect, so when I click any categories they’re going to a blank page.

But then I need to go into each entry again and assign each product to each of the new language-based categories don’t I??

If all my presumption are correct then (a) I am indeed an idiot and (b) my issue is solved and (c) you’re a very very patient man, thank you for your time 😊

Dave

       
Mark Huot's avatar
Mark Huot
587 posts
about 18 years ago
Mark Huot's avatar Mark Huot

@lithiumdave – i’d say you have it. your reasoning sounds fine to me.

       
First 5 6 7 8 9 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.