#reading-time in Spanish
3 messages · Page 1 of 1 (latest)
Hi @restive topaz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To translate the output of the reading-time remark plugin, you would need to modify the plugin code to support internationalization (i18n). Unfortunately, the reading-time package itself does not support i18n out of the box. However, you can create a custom function to translate the output text based on the user's language.
Here's a simplified example of how you might do this:
import getReadingTime from 'reading-time';
import { toString } from 'mdast-util-to-string';
function translateReadingTime(text, lang) {
switch(lang) {
case 'es': // Spanish
return text.replace('min read', 'minutos de lectura');
default: // English and any other languages you don't translate
return text;
}
}
export function remarkReadingTime() {
return function (tree, { data }) {
const textOnPage = toString(tree);
const readingTime = getReadingTime(textOnPage);
// Translate the reading time text
const translatedReadingTime = translateReadingTime(readingTime.text, data.astro.lang);
data.astro.frontmatter.minutesRead = translatedReadingTime;
};
}
In this example, data.astro.lang would be the language of the current user. You would need to implement a way to determine the user's language and pass it to the remark plugin.
Please note that this is a simplified example and might not cover all edge cases. For a more robust solution, you might want to use a dedicated i18n library.