Enable Android Studio spell checking on language specific strings.xml files - android

In Android Studio, spellchecking seems to be disabled for language specific strings.xml files (and I understand why it would be disabled by default).
But is it possible to enable it, to check values, for a couple of those files? ("fr/strings.xml" for example), or at least run it on demand.

To avoid or to enforce spellchecking you could add tools:locale to the <resources> tag in your string xml.
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
This tells Lint your resources' locale.
Source

Yes, go to Android Studio Preferences > Editor > Inspections > Spelling > Typo (check the box). Also make sure all scopes have been selected.
Incorrect spellings in the strings file show up with a light green line, clicking on which would show a message that it may be a typo.

Related

Does Android Studio Linter Offer An Option to look for default XML layout values?

1.) Is there any reason to have a default value inside an android xml layout?
Ex.) The TextView below has included a default value of
android:visibility="visible"
`<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="visible"/>`
Conjecture: Because this is a default value, it has no effect, and therefore is an unnecessary line of code in the XML file. Is that line of thinking correct?
2.) If there is no reason for default values to exist in Android xml files, is there a lint plugin available to point out default value code lines in android XML files?
It is my thought that a large number of code lines in XML files are default values, serving no purpose. What can we do to reduce these lines of code?
U can create a style with your default values and use it.
For example:
<style name="DefaultTextViewStyle">
<item name="android:visibility">visible</item>
</style>
to use this:
<TextView
style="#style/DefaultTextViewStyle" />
I had some hope that the Lint inspection Redundant default value attribute assignment for xml, run via Android Studio might have done what you're asking. You can run it as specified under the Manually Run Inspections part of the Android docs. i.e.Android Studio -> Analyze -> Run Inspection by name -> enter "Redundant default value attribute assignment", then select the scope for the Lint check.
Sadly though, it doesn't pick up the case you mention above. I'm just wondering if there's something I've missed, or if this isn't intended for Android xml in some way?

Android translation lint check - how to disable when only two out of 3 translations is required?

I have an app that usually translates into 3 different languages. Thai, indonesia and english (default). but on occasion i have a feature that is only applicable to thailand and english and indonesia does not need translations so i have left indonesia local string file empty.
Lets take a look at an example using android studios strings translations editor:
as you can see these a1,a2,a3,a4 are only required in thailand and english (default). so i left indonesia empty. Now lint gives off warnings that i am missing translations for indonesia. Is there any flag i can use to stop the lint check or is the best practice to still copy the string into indonesia even though its not used ?
There's no way to specify what you want exactly since your use case is I guess not widely used and it didn't make it into lint.
You can however use the tools:ignore="MissingTranslation"
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="foo" tools:ignore="MissingTranslation">1</string>
</resources>

Xml files in Android Studio - Remove spaces inside tags in layout files

On Android Studio is there a way to remove unnecessary spaces between the attributes and 'end tags' (">" and "/>") when formating xml files?
I can't see this configuration "Code Style" options.
Based on the accept answer below I got a configuration that work for me:
In Android Studio's Preferences, go to Editor > Code Style > XML. Then select the Android tab on the far right. There are options in this tab to customize the formatting of Android XML files (manifest, layouts, etc.). Make sure Use custom formatting settings for Android XML files is checked. Then you can just format that file like you do any other file Code > Reformat Code.
To get rid of the space before closing tags, go to the Other tab. Under Spaces make sure In empty tag and After tag name are un-checked.

How to alphabetically sort code in XML file inside Intellij IDEA 13 for android?

I used eclipse for training in android but now using Intellij IDEA 13. I am used to the graphical string editor of eclipse which can alphabetically sort the string.xml file for me.
I want to do the same in intelliJ but couldn't find any solution.
This is how code look like
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ActionBar App</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>
and I want to sort it alphabetically like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">Settings</string>
<string name="app_name">ActionBar App</string>
<string name="hello_world">Hello world!</string>
</resources>
How to do this ? Please help!
The arrangement feature allows you to setup rules to arrange the order this appear in a file. Arrangement of attributes, particularly for Android files, was add via IDEA-72907. You can get a predefined arrangement style for android by going to Settings > [Project Settings] > Code Style > XML {Arrangement Tab} Click on the "Set from..." link near the top right and select Preferred Style > Android. That will populate the XML style (and arrangement) settings with a predefined style that you can tweak.
That said, I am unsure if the arrangement feature has the ability to sort by the attribute's value. I know it can sort the attributes in a particular order. If I get a chance, I'll see if I can find the syntax to sort by the attribute's value. In the meantime, you can take a look.
Also, you can try either the Lines Sorter or SortSelection third party plug-ins. A bit more basic, but one might work for you.
I found this link Rearrange Attributes in Android XML Files with IntelliJ IDEA 13
I chose the second option.
As mentioned go to the settings/Editor/Code Style/XML/Arrangement
Reordering the arrangement and changing to be reorder by name:
This won't sort the strings.xml by name, so
copy and paste into an excel worksheet and sort by A-Z
I am posting this two years after the fact, but there's another way to sort lines in IntelliJ IDEA that I'd like to mention here -- i.e. by using the IDE's Vim features.
If you want to sort a range of lines alphabetically -- say, lines 3 through 6 -- just do the following:
Open the Tools menu and make sure that 'Vim Emulator' is checked.
Type the following command in your editor:
:3,6sort
That's it -- your lines will now be sorted. All you need to do now is disable Vim if you don't use it. You can do this by Opening the Tools menu and unchecking 'Vim Emulator'.
Note that this isn't an XML sort -- it's an alphabetic line sort so spaces and so on could get in the way of a successful sort. But for simple cases like the one you mention above, this should work.
Darryl
You can't sort XML elements by its attribute value, e.g. 'name' via File → Settings → Editor → CodeStyle → XML → Arrangement. You only can sort the attribute order inside a tag or can sort the elements by its tag name.
For Android there is a plugin called AndroidXMLSorter (can only sort by attribute 'name', only in Android Projects)
If the entries are written in a single line you can select the text and use: Edit → Sort Lines (no need for a plugin)

How to use tools:locale for strings.xml files?

Background
Lint has a relatively new feature, so that it will warn us about missing translation only for languages that we choose, but i don't get how to use it.
The problem
for some reason, Lint still warns me about languages that i don't intend on translating yet.
What i've tried
for example, currently i want to only have 2 languages : english ("en") and hebrew (which is sadly both "iw" and "he" ) .
so i have strings files in the folders :
values (for english)
"values-he" and "values-iw" (for hebrew) .
i've tried putting the new attribute in the english file as such :
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en,iw,he">
...
The question
what is the right way to do it?
Looking here it seems that it's to be used into resource files to indicate the default language. So you can specify only one locale code.
should correspond to a language
Moreover it seems to be used only to disable spell-checker
If you read the article:
This lets you tell the tools which language you're using in your
base values folder. For strings in for example values-de or values-en it's obvious, but not in the base "values" folder
It need only to know what is the language in the default "values" folder (the folder without any attribute).
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
You are already in right direction. Just need some modification. Like this manner:
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="es">
Now we know that the language used for strings in the default values folder is Spanish rather than English.
Used by: Lint, Studio (to disable spell checking in non-English resource files)
Reference Link: Go to here tools:locale
Thanks.

Categories

Resources