PDA

View Full Version : string resources - normalize or multiple copies are OK?



Varsuuk
January 27th, 2020, 13:46
I was wondering as I noticed I had the same word defined more than once in a strings.xml file due to being used in a place I had forgotten.

I can change to using the original one, but that begged the question for me - should I be concerned to limit duplication? Or is it OK to repeat certain string, in case you want to change one and not the other later or simply because it allows you to group strings by "topic" like
-- NPC Strings
label_npc_foo=
label_npc_bar=

...

label_char_bar=
label_char_zoinks=
label_char_othernonsense=

?


Like are all strings loaded and kept in memory or are they looked up as needed or are they looked up as needed once and inserter into the control as if hardcoded or ... etc?

bojjenclon
January 27th, 2020, 13:56
This sort of depends on your use case. The real (or at least, a common) reason to use a strings file is to support internationalization. I can tell you as someone who has to deal with internationalization in enterprise software, the norm is to use the rule: one string per unique use of the word/phrase.

The idea being that you can use the same word in English in multiple places, but the context may alter the translation, so even though its the same word you need to provide multiple translation sources.

That being said, if you're just making a simple extension or something you don't really ever intend to be put through a full translation process, then... it doesn't really matter. You can ultimately do what's easiest for you. Someone more knowledgeable of FG's internals can correct me on this, but I'd imagine unless you just have an absurd number of strings in your XML, that will rarely be your bottleneck/prime memory consumption source.

Varsuuk
January 27th, 2020, 16:48
Thank you :)

Yeah, my intent is to try to make it possible to internationalize it. (Assuming I ever finish)

Prior to moving to Linux back end server type work, I started in Windows writing cellular/paging comms software and my Notify! project often required translation. I remember putting out Spanish, French-Canadian, Portuguese and ... Mandarin ( it was troubleshooting that build a pain with UI messages completely unreadable ;) I can read Spanish and due to that and English, can diss out French and Portuguese well enough since I was familiar with whAt might appear. But Mandarin was like, send it to a translator.


I figure I will put them separate for now unless one obvious choice with one. Mainly so I can see where used (by the naming scheme) then after combine and name more generically. Unless there is no downside to multiple in which case may leave some as I can play with some capitalization etc without having to change all or break it into two then.