Syo timer on a multilingual site
I have a multilingual site that may be simultaneously operated by multilingual users who need a multilingual timer. So, I need not 1, but 3 languages simultaneously, depending on whether the page language is defined as en or ru or anything else. E.g. {{ .Site.Language.Lang }} returns the language object for the given page.
You can use the following steps:
- Declare all missing languages in the js code
- Save the page language in a variable
- Use the saved variable in the options of the
syotimermethod
// declare missing languages
$.syotimerLang.spa = {
seconds: ["segundo", "segundos"],
minute: ["minuto", "minutos"],
hour: ["hora", "horas"],
day: ["dia", "dias"],
};
$.syotimerLangheb = {
second: ['שניה', 'שניות'],
minute: ['דקה', 'דקות'],
hour: ['שעה', 'שעות'],
day: ['יום', 'ימים'],
};
// save page language in variable
const language = "{{ .Site.Language.Lang }}";
// init countdown
$('.selector').syotimer({
date: new Date(2024, 4, 9, 20, 30),
// use language variable
lang: language,
});
You can also update the language in runtime (after the countdown is initialized):
// init countdown
$('.selector').syotimer({
date: new Date(2024, 4, 9, 20, 30),
});
// some event
$('.button').on( "click", function() {
// change language
$('.selector').syotimer("setOption", "lang", "spa")
});
Dear John, thank you for the assistance. I considered this version, but still decided to stay with 2.0 as more convenient for me. Unminified js, added the new language (georgian), changed language codes to 2-letter ones, minified again. Works great! Best of luck!
Victor
On Sat, Feb 17, 2024 at 11:11 AM John Syomochkin @.***> wrote:
You can use the following steps:
- Declare all missing languages in the js code
- Save the page language in a variable
- Use the saved variable in the options of the syotimer method
// declare missing languages$.syotimerLang.spa = { seconds: ["segundo", "segundos"], minute: ["minuto", "minutos"], hour: ["hora", "horas"], day: ["dia", "dias"],}; $.syotimerLangheb = { second: ['שניה', 'שניות'], minute: ['דקה', 'דקות'], hour: ['שעה', 'שעות'], day: ['יום', 'ימים'],}; // save page language in variableconst language = "{{ .Site.Language.Lang }}"; // init countdown$('.selector').syotimer({ date: new Date(2024, 4, 9, 20, 30), // use language variable lang: language,});
You can also update the language in runtime (after the countdown is initialized):
// init countdown$('.selector').syotimer({ date: new Date(2024, 4, 9, 20, 30),}); // some event$('.button').on( "click", function() { // change language $('.selector').syotimer("setOption", "lang", "spa")});
— Reply to this email directly, view it on GitHub https://github.com/mrfratello/SyoTimer/issues/19#issuecomment-1950286325, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWAM5W3ACV24BY6QCDKQVTYUD6E5AVCNFSM6AAAAABC5TQ63CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJQGI4DMMZSGU . You are receiving this because you authored the thread.Message ID: @.***>
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.