Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming keys in resource files best practice

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:

  • editUserButton.label=Edit User...
  • editGroupButton.label=Edit Group...

or

  • editUser=Edit User...
  • editGroup=Edit Group...

or

  • user.edit=Edit User...
  • group.edit=Edit Group...

What scheme do you prefer and why?

like image 397
Christophe Herreman Avatar asked Mar 07 '09 09:03

Christophe Herreman


People also ask

Can the terraform file name be anything or it should follow some convention?

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 .


1 Answers

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.

like image 165
cherouvim Avatar answered Oct 18 '22 20:10

cherouvim