question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arrange string resources based on screens

See original GitHub issue

Describe the bug

Currently string resources are not organised correctly and are scattered in strings.xml file.

This should be fixed by following these points:

  1. Make sure that each string is getting used in one specific view only. For example Home is part of multiple views like Navigation Drawer, Home-Toolbar. So for this we should have separate strings for both.
  2. All strings related to one activity/fragment should be kept together by mentioning the activity name on top of the strings in a comment. Example: <!-- ProfileResetPinActivity -->
  3. All activities/fragment sections should be in correct alphabetical order based on activity/fragment name. (The actual strings name are not required to be in alphabetical order but the comments should be in alphabetical order). Example:
<!-- HomeActivity -->
<string name="random_string_related_to_home">ABC</string>
<!-- ProfileResetPinActivity -->
<string name="random_string_related_to_profile_resent_pin">ABC</string>
<string name="random_string_related_to_profile_resent_pin_2">XYZ</string>

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
rt4914commented, Mar 8, 2022

@rt4914 It would be very helpful if you can clarify these doubts before I get started:

  1. What comments do we put over Strings that are used nowhere but only declared?

If a string is not getting used anywhere, it should be removed.

  1. What comments do we put over Strings that are only used in a resource XML like menu? Do we create separate Strings if they are repeated in several resource files?

Don’t create separate strings right now. If its needed I will mention in PR. Comments can be related to menu file where they are getting used.

  1. For Activities and Fragments, do we put both XML and Kotlin Strings under the same comment?

Yes, a list of strings should be combined based on screen/feature and not on file-to-file basis.

  1. What about Strings used in Test files?

It would be great if they start with test_ prefix.

Sorry for the barrage of questions. There’s a lot of Strings and I don’t yet understand the issue properly. If it’s easier for you, we could do a meet.

The replies might change in PR because here I don’t have exact example with your questions. So I think better you create a PR with your judgement and there the conversation can be a bit easy. Thanks.

1reaction
adizcodecommented, Feb 26, 2022

I would like to work on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different strings for different screen sizes - android
Why is it happening? Edit: All the strings are located in values/strings.xml. For the "small"(first) device I need to override some ...
Read more >
String resources - Android Developers
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources ...
Read more >
How to name your string resources in strings.xml in Android?
The basic way a string resource is written in Android is the ... In my Summary Screen I want to show the message...
Read more >
How do you organize your String resources? : r/androiddev
Lets say you have a label "First Name" on two different screens in your app. Do you make two different string resource entries...
Read more >
How to Display Styled Text from String Resources in Android ...
In Android, we can store fixed strings in resources as well as hard code them in the front-end. When we store them in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found