2

I'm in a dilema where I'm translation a full mobile app where the translations are going to be a key value pair but I'm not sure how to name the key.

Should I name the keys describing what the text is, like (key: ok, text: Ok), or should I name the key from where it is on the screen/context, like (key: screenXButton, text: Ok) ?

Vencovsky
  • 351
  • 3
  • 8
  • Are the translations always going to be the same for a given source phrase across all screens? – Caleth May 11 '21 at 12:06
  • @Caleth yes, I will have one file with everything – Vencovsky May 11 '21 at 12:19
  • 1
    @Vencovsky: that was not Caleth's question. He was asking if a text like "Ok" maybe translated to "D'accordo!" on one screen, and "Passbile" on another (I took italian as an example). – Doc Brown May 14 '21 at 13:02

2 Answers2

4

Naming the key for it's intended functionality is the better option. After all, when you change the position on the screen, do you really rename it? It will still be a key representing OK.

Devolus
  • 213
  • 1
  • 2
  • 7
2

I recommend this

  • provide a general translation, where the key is based on the original text, and which you can reuse at several places (like key: ok, text: Ok)

  • for cases where the general translation won't fit, add a second translation where the key is the same plus a suffix indicating the context.

    For example, lets say you have a screen where "Ok" refers to this special kind of boat, you may use key: ok_dinghy, text: "OK-Jolle (in german). If there is one and only one place in your application where this translation is used, and you don't have any better idea of coming up with a context name, you may refer to it like Key:ok_screenXButton, but I would avoid this, if possible. Otherwise you end up in maintaining the name of such buttons not only in the screen code, but also in the translation table.

Doc Brown
  • 199,015
  • 33
  • 367
  • 565