9

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!

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
Santiago
  • 2,405
  • 6
  • 31
  • 43

4 Answers4

9

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>';
?>
JJ.
  • 5,425
  • 3
  • 26
  • 31
  • So, should I change that strings in http://timeago.yarp.com/jquery.timeago.js and make a separate Spanish version of the JS to include that one instead of the other? I thought it could be a better/cleaner way to do it. – Santiago Aug 23 '11 at 21:57
  • No, just download the spanish version which is already on that site and use it in your page. – JJ. Aug 23 '11 at 21:59
  • Ok, the thing is that I don't know how to do it. That was the question. – Santiago Aug 24 '11 at 01:59
1

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

daronwolff
  • 1,994
  • 21
  • 18
  • 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" }; } – Mohammad Baygi Oct 31 '17 at 20:46
0

You can reference different jquery.timeago.js when having one page per language, but this is static. To do it dynamically what you need to do is reference jquery.timeago.js in your page, at the end of your master or main file (or the page you use this library) you retrieve the object $.timeago and change the field settings according to the flag of your language:

if (typeof($.timeago) != "undefined") {
jQuery.timeago.settings.strings = {
        prefixAgo: null,
        prefixFromNow: null,
        suffixAgo: "il y a",
        suffixFromNow: "d'ici",
        seconds: "moins d'une minute",
        minute: "environ une minute",
        minutes: "environ %d minutes",
        hour: "environ une heure",
        hours: "environ %d heures",
        day: "environ un jour",
        days: "environ %d jours",
        month: "environ un mois",
        months: "environ %d mois",
        year: "un an",
        years: "%d ans",
        wordSeparator: " ",
        numbers: [] };
};

}

Mohammad Baygi
  • 604
  • 1
  • 7
  • 13
0

If you are using npm and installed timeago with it, then you could import local specific file from node_modules, you can have a try the following for french :

import fr from "timeago/locales/jquery.timeago.fr";
SayJeyHi
  • 1,559
  • 4
  • 19
  • 39
Farhad Lavaei
  • 452
  • 4
  • 7