I have recently came across some code where the variable names are in french, I could not use google translate because only part of the code needs translated, and it would not be that practical to copy and paste each of the variables into the translator.
How can i easily translate the variable names? what translator could i use?
Here is some french that i tried to translate.
#include <stdio.h>
int main()
{
unsigned int nombre;
unsigned int diviseur;
unsigned int reste;
for (nombre = 2; nombre != 0; nombre++)
{
for (diviseur = 2, reste = 1; (diviseur < nombre) && (reste > 0); diviseur++)
{
reste = nombre % diviseur;
}
if (reste > 0)
{
printf("%dn", nombre);
}
}
return;
}
But when i tried to translate the code using google translate i got this bad translation.
# include stdio.h
int main ()
{
unsigned int number;
unsigned int divisor;
unsigned int left;
for (count = 2, number = 0;! number + +)
{
for (divisor = 2, left = 1, (divisor <number) && (rest> 0) + + divider)
{
remainder = number% divisor;
}
if (left> 0)
{
printf ("% d n", count);
}
}
return;
}
6
Depending on your language, parsers or some sort of static checking tools may be available, letting you to extract the list of variables.
For example, PHP has a tokenizer, while for JavaScript, one can use jslint. For C#, there is StyleCop which will, with minor configuration changes, highlight every variable written in a language other than English (or containing spelling errors).
Once you get the list of variables, use a translator tool of your choice and get a translation as a table where the first column is the Russian name, and the second one — the English translation.
This step would be done mostly manually. I don’t know any automated translator which will be able to deal with the variable name such as iCountActivations
. Regular expressions can help to get rid of prefixes or translating camel case into separate words.
Then use refactoring tools to rename the variables. Refactoring tools will take care of renaming the variable in every place where it is used, and rename only this variable.
Finally, use search to check manually that there is anything left.
Warning: be prepared to obtain meaningless variable names because of a bad translation. If code quality matter, prefer to translate the source code by a person who knows both Russian and English and who is also a programmer and is able to understand the source code to translate. Such people are easy to find, I believe (I’m one of them and know a lot of developers who know languages other than English), but very probably, they wouldn’t do it for free.