How to modify Arduino DS1302 Library to use in your language

Arduino Uno

I decided to write this tutorial on English, even if my natural language is Romanian, to help others understand what this post is about.

During the development of one of my Arduino projects, i wanted to display the Time and Date on my own language. I started to look around over the Internet, but no tutorials or post are available about how to do it. So, I decided to look around the libraries i use for the DS1302 RTC module for Arduino Uno. I found out that it is actually very easy to translate the names of the day of week and months, but i didn’t wanted to use only my language, because the product i develop is intended for other language speakers too. So, i need it to be multi language.

This is how you should modify the libraries files to translated in your own language.

The file you could download is already modified for Romanian language, but it is very easy to modify it for any language. I will show you bellow how to do it.

So .. let’s start edit:

In library DS1302, you will need to edit the files DS1302.cpp and DS1302.h.

On the DS1302.cpp file you will need to add the following lines, right after the function: char *DS1302::getDOWStr(uint8_t format). Please note that i added the country code between DOW and Str in the function. You can add your own country code to make it unique.

// Added for Romanian translation of Day Of Week (DOW)

char *DS1302::getDOWRoStr(uint8_t format)
{
char *output= „xxxxxxxxx”;
Time t;
t=getTime();
switch (t.dow)
{
case MONDAY:
output=”Luni”;
break;
case TUESDAY:
output=”Marti”;
break;
case WEDNESDAY:
output=”Miercuri”;
break;
case THURSDAY:
output=”Joi”;
break;
case FRIDAY:
output=”Vineri”;
break;
case SATURDAY:
output=”Sambata”;
break;
case SUNDAY:
output=”Duminica”;
break;
}
if (format==FORMAT_SHORT)
output[3]=0;
return output;
}

// End of Romanian translation

On the same file, you will also need to add the following lines, right after the end of the char *DS1302::getMonthStr(uint8_t format) function. You also need to notice the country code inserted between Month and Str

// Added for Romanian translation of Month

char *DS1302::getMonthRoStr(uint8_t format)
{
char *output= „xxxxxxxxx”;
Time t;
t=getTime();
switch (t.mon)
{
case 1:
output=”Ianuarie”;
break;
case 2:
output=”Februarie”;
break;
case 3:
output=”Martie”;
break;
case 4:
output=”Aprilie”;
break;
case 5:
output=”Mai”;
break;
case 6:
output=”Iunie”;
break;
case 7:
output=”Iulie”;
break;
case 8:
output=”August”;
break;
case 9:
output=”Septembrie”;
break;
case 10:
output=”Octombrie”;
break;
case 11:
output=”Noiembrie”;
break;
case 12:
output=”Decembrie”;
break;
}
if (format==FORMAT_SHORT)
output[3]=0;
return output;
}

//End of Romanian translation

Now, we also need to modify the other file, DS1302.h, and add a couple of line. Please note that in this file you need to add the same names ass before. On class DS1302 section on the file, you need to add :

    char    *getDOWStr(uint8_t format=FORMAT_LONG);
// Added for Romanian translation of Day Of Week (DOW)
char    *getDOWRoStr(uint8_t format=FORMAT_LONG);
char    *getMonthStr(uint8_t format=FORMAT_LONG);
// Added for Romanian translation of Month
char    *getMonthRoStr(uint8_t format=FORMAT_LONG);

In my case, i added the country code of Romania, Ro (see it in red color).

In Arduino IDE, when you call the function, you can use getDOWRoStr(FORMAT_LONG), to display it in Romanian(in my example), or  getDOWStr(FORMAT_LONG) for English(default for standard library).

If you are from Romania, and need to buy a DS1302 sensor, here is a link from where i purchase it, for as low as 10 Lei: RoboRomania.ro

If you would like to download the modified library, you can do it here: DOWNLOAD .

If you have any comments, please use the comments section bellow.