Reputation: 2873
I created DAOs for my database tables. In SAP ABAP you can have additional text-tables which contain the language-dependent texts (language-code is part of the key). Currently I create DAO-instances right at the beginning of the program (Dependency Injection) and pass them a language-key which effectively binds the DAO to a specific language and let's the DAO read texts only from that specific lagnuage.
However later in the program I am required to get texts from another language. How do I cope with this?
Explicitly include the language-key in the DAO's crud and find-by methods? This would require any client of the DAO to also expose the language-key it its methods and to properly pass it on to the DAOs, which smells. e.g. method read(id, languageCode) returns <thing>
. Additionally I want domain-objects to know nothing of DAO/infrastructure-crap.
Give the DAO itself a language-aware interface that allows me to create another instance of the DAO that is bound to a different language (factory). This requires me to explicitly access the DAO, which are otherwise hidden, smells too. e.g. method createWithLang(langCode) returns <DAO>
Make the domain objects language-aware which means language-dependent methods explicitly expose the language-code. But then the domain objects already need to know all texts in all languages to return the proper one or they need direct access to some DAO to reload the proper text. Then, doing this lazily is an additional challenge (regarding ABAP OO).
Every advice greatly appreciated
Upvotes: 0
Views: 136
Reputation: 18493
I would probably add a parameter to the getter and setter methods that deal with language-dependent texts and set its default value to SY-LANGU
. This way, l_foo = lr_bar->get_baz_text( )
will implicitly get the text in the language the user logged on with, and l_foo = lr_bar->get_baz_text( l_target_language )
will retrieve the text in any other language. You might want to pre-fetch the text in the current language when creating the object and use a hashed table to store the language-dependent texts.
Upvotes: 1
Reputation: 4592
In SAP, the selected language is part of the session. Your program could also have a globally available 'session' singleton where you store the user language choice.
Upvotes: -1