banner



How To Create Dictionary In Android Studio

Shared a project dictionary for Android development

Pedro Veloso

I believe any passionate craftsman will aspire to be his/her best at what they do. In software devel o pment there are many that stand by the moto that good code is self-documenting, which I personally find easy to apply to methods, parameters and variable declarations. Documentation is still necessary at a Class level for example, and to act as the glue that describes the expected flow within an app, and for a myriad of other different reasons. If a developer holds these coding standards true it than stands that documentation should employ the same precision, coherence and clarity as the code itself.

Most projects I've worked in have a set of words that are specific to that business and non existent in conventional spellchecking dictionaries. Spellchecking is an efficient way of focusing on what you want to say rather than worry about getting every single letter correct. If you're as curious as I am, you probably glimpsed at the text on the image above. Did you notice that the word "cryptocurrencies" is actually misspelled? Maybe you did, maybe you didn't, it doesn't matter because you're not a spellchecker, the same way you're not a compiler or a lint tool. If you're spending time looking for these things, you could likely be using attention to details for something else far more important 😉.

It is the nature of most software projects to be constantly evolving, and by setting the appropriate framework in place you can stir it in the right direction and you move forward! In this post I'll show how to leverage the existing spellchecking tool capabilities to work for you and your team. Don't get caught in the trap of ignoring the spelling of your work because of the spreading of false-positives.

The Out-of-the-box experience

Whenever the IDE flags a certain work is misspelled it will also provide an option to "Add to Dictionary", and that word won't be flagged again. That is, for you at least, because sadly this dictionary is user-specific and will never be reusable by your team.

There is a bunch of tickets on JetBrain's tracker where different users ask for better support for sharing these dictionaries, as can be seen here. These have been on the tracker for a while, and since this issue does not affect immediate productivity it is likely that it could be a long time until JetBrains even considers this. However, some basic support exists if you know how to make use of it. READ ON!

Include a dictionary on the project VCS

I'll briefly describe how Android Studio (and for that matter any other IDE based on IntelliJ Idea) manages a project's dictionary.
When you choose the option add a given word to the dictionary, IntelliJ searches the directory idea/dictionaries from the root of your project and creates or appends this word to an XML file named after your OS login username. So for example, my computer's login username is "pedro", so that directory will contain a file named pedro.xml the moment I add my first word to the dictionary by using the contextual menu on the IDE. Now here comes the cool part: any file present on this directory is considered for the dictionary words used by the IDE! JetBrains' reason behind using the username for the filename is quite simple, it reduces the possibility of merge conflicts from adding words to the dictionary if you decide to add this directory to your Version Control System, VCS for short.

Now that you understand this, there are 2 main options here:

Options 1: A dictionary file per Developer

You can simple have every developer add their words to dictionaries, and as long as the directory idea/dictionaries is being tracked by your VCS all anyone needs to do to contribute to the dictionary is to use the IDE's built in support for adding new words to the dictionary.

Option 2: Manually created dictionary file

Since the IDE will pick up any XML file formatted in this way, that means you could create a file named something other than a username. Having one single file might be useful if you plan to re-use this file on other projects that share the same terminology, thus having all the words for a given context on one single file.
If you have multiple developers committing their own files, it may also happen that they add the same words on their respective dictionaries. That would not prevent the words from being recognized but you end up with unnecessary duplication of dictionary words in the project.

At the time of writing for this article there is no way to have the IDE write to a dictionary file other than the one with your username, so you'd have to manually edit this files. Fortunately the syntax is quite easy. This is the entire contents of an example of a dictionary file:

<component name="ProjectDictionaryState">
<dictionary name="project-dictionary">
<words>
<w>bitcoin</w>
<w>cryptocurrency</w>
</words>
</dictionary>
</component>

The property name of dictionary reflects the name of the file, which for this example was project-dictionary.xml. Make sure that property has the exact same name as the dictionary file's filename, otherwise the IDE will remove the file.

If you opt for this solution you should consider adding just the manually create files to your VCS while still ignoring the rest of the idea/dictionaries directory. This way if a developer adds a word to their dictionary by pressing "'Add to Dictionary" on the IDE, that file will not end up on everyone else's computer.

Which one to choose

Like most decisions in software development, the right choice for you highly depends on your project and team's requirements.
You can also leverage the capabilities of a VCS and have different options in between the two. For instance, while you can ignore the directory and track only specific files, like mentioned on the 2nd option, you might also just track the entire directory if you decide to offer a mix of IDE-generated personal dictionaries and manually curated ones.

Final notes

The IDE only scans the dictionary directory when it launches. So if you're missing some content after pulling in changes from your VCS just re-open it.

If you've found this article useful let me know in the comments below! Suggestions and corrections are always welcome too :)

How To Create Dictionary In Android Studio

Source: https://pedronveloso.medium.com/share-dictionaries-for-android-development-fc2223aa827e

Posted by: garciawhar1968.blogspot.com

0 Response to "How To Create Dictionary In Android Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel