farahat80/react-open-weather

Support full Spanish lang in all the widget

Closed this issue · 7 comments

Is any possibility to change the day's name to another language? Now the only two elements that are been translated are Wind and Humidity.
For example in English, appears Fri 11 December and in Spanish, should be Vie 11 Diciembre.

mpsb commented

Kindly check your API URL and see if you have the lang parameter:
https://stackoverflow.com/questions/49555188/how-to-change-description-language-in-openweathermap-api-in-android

If you don't have it, this could be a possible feature to test out.

I think is related to a bug in moment library, because when do this line:

formatDate(dte, lang) {
if (dte && moment(dte).isValid()) {
moment.locale(lang);
return moment.unix(dte).format("ddd D MMMM");
}
return "";

In utils.js file, the lang arrives correct, for example, 'es', but when do moment.locale(lang); that's returns 'en' and the return parse the unix dte in 'en' language. I don´t know if only happens to me or not

@ManuelRios94 version 1.1 has been released, its a complete refactor of the component, "moment" has been removed and replaced by dayjs, in the readme you will now find the possibility to override the dayjs locale from outside the component
please let me know if the new version solved your issue

I tried importing and use dayjs before rendering the component and in the first component of my app, but do not do the override. Do I need to import it as a script in the HTML file?, but with this new release the hook retrieve the data object with the Date information I can do a translation between the retrieved data and the render of the component!

May be in the utils files:

export const formatDate = (dte) => {
if (dte && dayjs().isValid(dte)) {
return dayjs.unix(dte).format('ddd D MMMM');
}
return '';
};

export const mapCurrent = (day, lang) => {
return {
date: formatDate(day.dt, lang),
description: day.weather[0] ? day.weather[0].description : null,
icon: day.weather[0] && getIcon(day.weather[0].icon),
temperature: {
current: day.temp.toFixed(0),
min: undefined, // openweather doesnt provide min/max on current weather
max: undefined,
},
wind: day.wind_speed.toFixed(0),
humidity: day.humidity,
};
};

The formatDate was called with lang in parameter but the function does nothing with that parameter

@ManuelRios94 i think i know why my suggestion doesnt work, its because the library uses its own dayjs so even after you try to set the locale from outside its not being applied to the dayjs inside

i am working on a solution now

@ManuelRios94 version 1.1.3 now fully support Spanish language, the code now import the dayjs locale internally without any external solution