Reputation: 2182
When you talk about AOP (Aspect Oriented Programming) you should think about some crosscutting concern that it can be applied to.
One of such crosscutting concern as I think is internationalization.
Can some AOP framework be used to solve such problems as internationalization? Does anyone have some experience of using it?
Upvotes: 0
Views: 276
Reputation: 18662
Everything could be used for I18n to some extent. However, chances are high that you'll be re-inventing the wheel or you will totally screw things up.
Now, let's think about it for a moment. The typical example of cross-cutting concerns, thus typical use case is logging. But of course you can use it for anything else, the only prerequisite is, you need to have thing that you do repeatedly and more or less the same way.
Can you do I18n this way? Sure, you may use it to:
However, I am not so sure about other I18n concerns, like translating strings (possible, but... wait for it) and message (vel string) formatting. Actually, I have hard times to imagine message formatting with all the placeholders, valid plural forms and such. It may be possible, but I can't see it at the moment.
Last, but not least. Just because you can use AOP for I18n, it does not mean you should. The common criticism of AOP is, it makes the code harder (or even impossible) to understand. Sometimes it is just better to use plain, old (times flies, you know) Inversion of Control, rather than the concept that few people really understand.
Please also keep in mind, that I18n is not just a feature that you can add whenever you like, but something that needs to be integral part of an application from start to finish. And to make things worse, it is not just about the code, but also about User Interface and the whole International User Experience.
It is pretty unlikely, that you'll (or anyone to be perfectly honest) will find the Holy Grail of I18n programming just by using AOP or any other programming concept. It is just too difficult problem to be solved in such an easy way...
Upvotes: 3