Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Timeago timestamps: How to choose language?

I'm sure this is a dumb question, but I really don't know how to do it.

I'm using timeago jquery plugin: http://timeago.yarp.com/

And it has locale support for multiple languages.

I'm translating my site from English to Spanish, I'm using PHP to do this. So, I would like to use timeago in both languages too.

I found this strings for multiple languages: https://gist.github.com/6251

But how do I use them?

Thanks!

like image 832
Santiago Avatar asked Aug 23 '11 21:08

Santiago


2 Answers

You can get the spanish .js file for timeago here: https://gist.github.com/6251.

Reference the correct .js file in your website where you are loading an English or Spanish page.

Ie in file page_spanish.html:

<script type="text/javascript" src="timeago_spanish.js"></script>

Ie in file page_english.html:

<script type="text/javascript" src="timeago_english.js"></script>

Or if you are doing this via one PHP script, toggle based on a variable:

<?php
    if $page_lang = 'SPANISH' then
        echo '<script type="text/javascript" src="timeago_spanish.js"></script>';
    else if $page_lang = 'ENGLISH' then
        echo '<script type="text/javascript" src="timeago_english.js"></script>';
?>
like image 71
JJ. Avatar answered Oct 11 '22 23:10

JJ.


Im using this code.

main.js

if (typeof($.timeago) != "undefined") {
    jQuery.timeago.settings.strings = {
        prefixAgo: "hace",
        prefixFromNow: "dentro de",
        suffixAgo: "",
        suffixFromNow: "",
        seconds: "menos de un minuto",
        minute: "un minuto",
        minutes: "unos %d minutos",
        hour: "una hora",
        hours: "%d horas",
        day: "un día",
        days: "%d días",
        month: "un mes",
        months: "%d meses",
        year: "un año",
        years: "%d años"
    };
}

from this link

like image 27
daronwolff Avatar answered Oct 11 '22 22:10

daronwolff