4

I am relativly new to Java and I am writing small programs to practise. Therefore I write a lot of comments in my programs to understand the written code easier, whenever I have to make a change.

Because I am a German programmer I write the comments in German.

I was wondering whether it is possible to write the comments in different languages in the same code, so when I have questions for English forums/portals or need to share to code to a certain language group I can simply attach a code with the English transalation of the comments.

Or is there a "codex" to write everything in english.

A BTW question: Is there a recommended way to write multilingual programms ? Regarding managing Strings etc.

greets

THE-E

THE-E
  • 193
  • 3
  • 4
  • 21
  • If you're speaking about the javadoc comments. You could always check this : http://stackoverflow.com/questions/1482392/how-to-be-multi-language-to-javadoc – user2336315 Jun 06 '13 at 11:18
  • For multilingual support, the classical way is to use a `ResourceBundle`. It has some drawbacks though. If you are ready to play, you may want to look [here](https://github.com/fge/msg-simple). – fge Jun 06 '13 at 11:21
  • For the comments, I (also German) tend to stick to the English language. This makes it easier to share the code (either on SO or with coworkers) and, at least from my experience, this seems to be SOP. For Strings in the program, there are certain possibilities, mentioned in other comments/answers. – Dominik Sandjaja Jun 06 '13 at 11:33

3 Answers3

2

Store you JAVA source files in 'UTF-8' and at compile time specify -encoding UTF-8 switch to javac. Other build systems ( Ant, Maven ), and IDEs also allow to specify the encoding.

This way you do not depend on a platform specific encoding and will be able to share your files throughout the world in any language that you want.

For managing String resources, you should consider using ResourceBundles. The simplest implementation of which is PropertyResourceBundle.

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
  • This is a language question (English, German, Chinese, etc), not an encoding question... – jlordo Jun 06 '13 at 11:18
  • @jlordo. No, at the hart it is `encoding` issue, because I don't know which default platform encoding will support German, Chinese, etc. – Alexander Pogrebnyak Jun 06 '13 at 11:20
  • I understand what you mean, but I think you misread the question. He is basically asking: I write my code comments in German, what should I do when posting my code on stackoverflow, to have the comments appear in English. – jlordo Jun 06 '13 at 11:22
  • Read OPs comment below Uwe Plonus answer. – jlordo Jun 06 '13 at 11:25
  • @jlordo. No, I did not misread it. `I was wondering whether it is possible to write the comments in different languages`. This, I guess, means that the OP wants comments in different languages coexist in the same source file. – Alexander Pogrebnyak Jun 06 '13 at 11:25
  • Sorry, I think I probably wrote my question not clearly enough. In a short form: I want to write a code with German and English comments, so whenever I share it, all I have to do is select the needed language and the comments will appear in the needed language. – THE-E Jun 06 '13 at 11:30
1

Technically it is possible to write comments in any language. Sometimes examples here on So contain comments in german, french, italian or even greek or chinese

When choosing the language for your comments keep in mind that everyone in your team should be able to understand them.

Another thing that may force you to write code and comments in a certain language are company policies. At a former employer (a bank) i had to write both code and comments in german. which can be annoying when you have a variables that are database keywords...

Marco Forberg
  • 2,634
  • 5
  • 22
  • 33
0

You can write your comments in any language you wish.

To ask questions in english forums it is an advantage to have comments in english (but not necessary).

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
  • I am aware of that, but I mean to write comments in different languages at the same time. For example I write the following code: int a; //Eine Int-Variable I will have to delete this comment and replace it with the English comment. [CODE] int a; //An Int-variable[/CODE] But this would be really annoying to do everytime I ask a question or give the code to someone speaking a other language. – THE-E Jun 06 '13 at 11:20
  • So then I don't understand your question... What should be the result? – Uwe Plonus Jun 06 '13 at 11:27
  • I want to write a code with german and english comments. When I want to share my code to an English community/group I select English and the comments will appear in the English-version. If I chose German the code will appear in the German-Version. In my case I have a program with german comments, but if I want to share my code with English comments, I have to replace the German comments. Basically I would need to maintain 2 different versions of the code to have comments in 2 different languages. I could write all the versions back to back, but that get confusing with more than 2 languages. – THE-E Jun 06 '13 at 11:46