Announcement

Collapse
No announcement yet.

Detecting current Language

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Detecting current Language

    We recently added a translate widget to our site. I'm trying to switch some content based on the current language selected.

    I was provided with this script sample.

    Code:
    var current_lang = document.getElementsByTagName('html')[0].getAttribute('lang');
    This should get me the current language. Now I want to do something like:

    Code:
    <mvt:if expr="'es' IN g.current_lang">
    // do this
    <mvt:else>
    // do something else
    </mvt:if>
    I'm just spinning my wheels. Seems like it should be simple...
    Ron Frigon
    Jedi Webmaster Obi-Ron Kenobi

    #2
    It looks to me like a timing problem.
    Template code runs in the server, before the page is sent to the browser. Javascript runs in the browser, after the template has been completely rendered. So you can't use an mvt:if to check the value of a variable that won't have a value until after the template has been rendered.
    Kent Multer
    Magic Metal Productions
    http://TheMagicM.com
    * Web developer/designer
    * E-commerce and Miva
    * Author, The Official Miva Web Scripting Book -- available on-line:
    http://www.amazon.com/exec/obidos/IS...icmetalproducA

    Comment


      #3
      Originally posted by Kent Multer View Post
      It looks to me like a timing problem.
      Template code runs in the server, before the page is sent to the browser. Javascript runs in the browser, after the template has been completely rendered. So you can't use an mvt:if to check the value of a variable that won't have a value until after the template has been rendered.
      Exactly. If you can't do what you need via JS (which you might), then check if:

      &mvt:system:http_accept_language; or &mvt:system:miva_language; is coming from the customer's browser or an internal variable miva uses. (don't know--never used).

      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment


        #4
        Thank you for the help guys. All makes sense.
        Ron Frigon
        Jedi Webmaster Obi-Ron Kenobi

        Comment


          #5
          Originally posted by Ron Frigon View Post
          Thank you for the help guys. All makes sense.
          Ron Frigon, we've been contemplating implementing such a solution. Could you please report back a few months from now and let us know how it worked out for you?

          Also, is there any analytics involved to determine which traffic is seeing what and order placed?
          Thank you, Bill Davis

          Comment


            #6
            William Davis Sure, I'll report back in a bit. Give me a nudge if I forget...

            We're using the paid version of GTranslate, the sub-directory version. The Sub-domain version was too problematic. This does not work well with Miva out of the box but hopefully they have it figured out now. For example cart contents would get cached causing all kinds of problems. Disable cache when an item is added to cart...

            GTranslate does have some basic analytics. You'll need to create some custom events, etc., for GA4 based on language selection which will require some js foo.

            GTranslate does update canonical urls and also updates the html lang="en" based on language selected. You also have the ability to edit on site translations directly from your web browser which is pretty slick.

            So far, as far as SEO is concerned, it seems to have increased our visibility for the alternate language. I haven't seen any negative issues. We have our setup limited to English/Spanish only.
            Ron Frigon
            Jedi Webmaster Obi-Ron Kenobi

            Comment

            Working...
            X