Does anyone have any recommendations on naming keys in resource files? For instance, do you base the name of your key on the text that needs to be localized or on the control that uses the text?
Say you have an edit button in several screens (one to edit a user, one to edit a group). You could use the following keys:
or
or
What scheme do you prefer and why?
Resource names are nouns, since resource blocks each represent a single object Terraform is managing. Resource names must always start with their containing provider's name followed by an underscore, so a resource from the provider postgresql might be named postgresql_database .
I prefix my literals by usecase or action classname. eg:
PlaceOrder.invalidId=Invalid id for order {0} PlaceOrder.success=Your order {0} was successful PlaceOrder.fail.visa=Your visa was ... PlaceOrder.fail.communications=We could not... PlaceOrder.submit=Buy now Login=Login Login.fail=Your credentials did not... Login.alread=You are already logged in
This way you avoid collisions:
EditStudent=Edit EditClass=Edit EditCourse=Edit Course
...and can also find what you need easier.
Another way I group is by entity:
Person.id=# Person.name=First name Person.surname=Surname
These can appear as headers on tables with the entities. It saves you in cases such as this:
Person.id=# Class.id=# Course.id=Course Id
Lastly by providing context in the property keys you can save yourself from false translations. For example I once had:
no=no
which was being used as an id (#) table header on the top left cell, but our french translator did this for French:
no=non
... he thought it was the word "no" (negative of yes). :)
Last (but not least) prefixing with classname will help you when you want to refactor/rename classes and quickly update these property keys without having to look at the templates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With