Log in Sign up

Translate the months on my template?

Maybe there is a way to name the months personally, by manually entering new names for each month. Or immediately change the language in which the names of the months are displayed in the posts, without changing the format. If possible, I am interested in both options.

I understand that it should be done in script.js, but I don't know what to add and on which line. Tell me please.


a year ago, 3 replies   developers   translation   Edit question

You'll need to write the script specific to the language you'd like but something like this should work for say French:

var dictionary = {
    January: "Janvier",
    February: "Février",
    March: "Mars",
    April: "Avril",
    May: "Mai",
    June: "Juin",
    July: "Juillet",
    August: "Août",
    September: "Septembre",
    October: "Octobre",
    November: "Novembre",
    December: "Décembre"
};
document.querySelectorAll('span.relative')
    .forEach(function(node) {
        if (dictionary[node.innerHTML.trim()])
            node.innerHTML = dictionary[node.innerHTML.trim()]
    });

Make sure to update the selector to match the HTML of your template

Answered a year ago · Edit answer

Thanks, but I still don't quite understand. How to properly insert it into a magazine template? How do I update the selector for my template? Pasted this code at the end of script.js if I understand correctly, what are the next steps?

Answered a year ago · Edit answer

Adding this to your template's script.js file is the right location. You'll need to use your browser's developer tools to identify a CSS selector suitable for uniquely identifying the tags on your page which contain dates. Once you've done that, you'll change the argument passed to querySelectorAll in the script above with the selector you identify.

If you're not interested in modifying your template's source code, an alternative to all this, of course, is to use the point-and-click interface to select a date format which doesn't contain the month name, just numbers, e.g. 2023-10-07

Answered a year ago · Edit answer