Jason Connery

no time.

Dev Tool: Accented Strings

I’m working on an app at the moment that will be localised into multiple languages. Android support for multiple languages is decent. You can provide alternate strings files, alternate layouts, images, etc. But even with the provided support old habits die hard and it can happen that you hard code a string in somewhere and forget about it. Perhaps it was just a temporary dev thing, but you forgot about it. Temporary has a habit of becoming permanent.

There are some lint warnings for this, but an additional option available is a special locale zz-ZZ called Accented English. One can provide alternate resources with the zz qualifier, values-zz , with alternate english. Maybe longer and more verbose strings to test layout flexibility, accented characters like Sëttîñgš , so one can see at a glance when testing on device what strings are coming from resource files, and what might be hardcoded / server side. So you provide alternate versions, and any time you notice a non-funky string you can ponder whose responsibility it is to provide alternate versions.

Typing all those by hand is annoying, so I wanted a shortcut. While googling, I found several ways to go from accented to normal english, like Sëttîñgš –> Settings. But I couldn’t find any tools to go the other way around. Nothing for converting normal strings to accented strings.

So I wrote a little groovy script to do it for me. It really just does the bare minimum, but might come in handy. it works like so:

If you have an android strings file, you can generate a new one you can include in your values-zz folder. If we take a sample input:

1
2
3
4
5
6
7
8
9
$ cat strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">SampleApp</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="number_of_fish">You have %d fish!</string>
    <string name="hello_name">Hello, %s!</string>
</resources>

We can pass the file to the script to create a new one. The output is just printed, so redirect to a file or something if it looks ok

1
2
3
4
5
6
7
8
9
10
 $ groovy Accenter.groovy ../../../../examples/strings.xml

  <?xml version="1.0" encoding="utf-8"?>
  <resources>
      <string name="app_name">SámpłëÄpp</string>
      <string name="action_settings">Sëttîñgš</string>
      <string name="hello_world">Hëłłö wörłd!</string>
      <string name="number_of_fish">Yöü hávë %d fîšh!</string>
      <string name="hello_name">Hëłłö, %s!</string>
</resources>

Notice that formatting strings aren’t affected to %s doesn’t become %š

Grab the code

You can fork it on github right here

it might have a tonne of bugs and shortcomings, and it might mangle things it shouldn’t like http links. I’ve only added a few exceptions so far.

Why groovy?

With the new android build system using gradle and groovy, I thought it’d be fun to try it out. Seems like an interesting language. I wonder if something like this, generating -zz resources could be done as a plugin as part of the assemble processs.