-
Notifications
You must be signed in to change notification settings - Fork 46
Description
I found several reasons why .lang()
methods should be removed, and maybe replaced with some other, decoupled and centralized way to manage localization. So let me explain why:
They make it harder to resolve git conflicts
Recently, I wanted to rebase a branch on top of master. It was basically a medium-sized update with partial rewrite of some classes, so not a simple no-brainer this time.
Then, the problem emerged:
- local branch changed some business logic
- remote updated default translations with
.lang()
method
This problem shouldn't even be present in the first place, but because both commits touched the same file it couldn't be resolved automatically. Because the .lang()
method exists, we can unintentionally introduce git conflicts on the i18n<--->logic boundary. It's not something you think about, until you have this problem and you have to resolve the conflicts manually.
I'm sure you know that the convention of hardcoding strings is considered bad practice. Proper i18n should have it's strings stored in a .lang/.string.xml
or similar file -- they act as a centralized "dictionary" that is easy to find, edit and maintain.
These conflicts require developers to resolve the language problems manually, but we can't/don't want to make decisions about language when we're just changing code. Often solving conflicts boils down to "accepting theirs" on language and "accepting ours" on code, but everyone can make a mistake and produce a faulty commit (either we skip a better translation or reject valid code due to missclick).
Another thing...
...keys are mostly immutable, while translations and code may change frequently
A thing once added will keep it's translation key mostly forever/until renamed/removed, so we can think of them as mostly immutable. Translation strings on the other hand can get sudden bursts of git activity even several times a day. Code changes can happen daily. Having to resolve the conflicts by hand can add otherwise redundant overhead to workflow.
Yet another thing -- it's hard to localize strings when they are scattered all over the codebase.
Some objects will use .lang()
, others won't. Without centralized place to manage translations it's becoming hard to locate correct place for strings.
I've seen at least one example, where developers write some custom language managing code
They make it harder to integrate translation service, e.g. Weblate
No centralized spot to manage all the translations
Sum up
IMO .lang()
methods encourage bad practices and make it harder to work with. In conclusion - I would get rid of them. What do you think?