23

I have an app with several translations, and I want to delete some strings.

How can I refactor and delete them only once for example in the default strings.xml file and automatically propagate the deletion to the other strings.xml file of other translations?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Addev
  • 31,819
  • 51
  • 183
  • 302
  • 1
    xml files are created at build time. You can't alter them at runtime. – DroidDev May 29 '14 at 08:07
  • 1
    I want to delete the strings with eclipse before compiling, the strings are dead because I do not use it anymore – Addev May 29 '14 at 08:08
  • @DroidDev He just says that after a refactor he no longer needs a string, and so he wants to delete it from every other language xml at once – Sergi Juanola May 29 '14 at 08:08
  • Just identify the dead strings by using Lint and remove them manually. – Phantômaxx May 29 '14 at 08:12
  • I don't understand the down votes. The question is clear and the problem exists. The tags are the only issue here. This is not a java question is an adt/eclipse or Android Studio question. @Addev can you retag it properly? – Brais Gabin May 29 '14 at 09:51

5 Answers5

42

You can remove all translations by "Translations Editor" in Android Studio.

  1. Select string's key
  2. Click on "Remove key" button
  3. Uncheck all checkboxes in "Delete" dialog
  4. Click "OK" button in "Delete" dialog

enter image description here

Dmitry Ognev
  • 856
  • 1
  • 9
  • 9
  • Does it also show ones? I don't see them when I open the translation editor – qwertzguy Feb 07 '20 at 03:02
  • it doesn't support plurals, but i think u can build your plurals on string resources like that @string/singular_pattern @string/plural_pattern ... – Dmitry Ognev Feb 17 '20 at 12:49
15
  1. CTRL-H
  2. select tab File Search
  3. check regular expression
  4. input \R\s*<string name="string_name">(.|\R)*?</string> and don't forget replace string_name to actual string name.
  5. file name patterns set *.xml
  6. Press Replace...
  7. Leave replace field empty.
  8. Press Preview >
  9. Check all replacement.
  10. Apply changes by press `Ok'
Enyby
  • 4,162
  • 2
  • 33
  • 42
2

Now you can do it easily with Translations Editor. To open it click on the Open editor on the top right corner in xml file. Then in the editor right click on key you are want to delete and press Delete Keys(s)

Yvgen
  • 2,036
  • 2
  • 23
  • 27
0

default strings.xml file and automatically propagate the deletion to the other strings.xml file of other translations

ADT does not support this operation. You need to get rid of the text from all your XML files yourself, which should not be hard task anyway, as it would be sufficient to do project global search (in Eclipse CTRL-H), set file mask to *.xml and search for your string key. Then just remove this file from each file found.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • 1
    Not hard, but highly cumbersome. I have just deleted a class in my project resulting in a hundred unused strings and drawables. Now I have to go through the 30 language files and 5 drawable folders to delete them one by one! Not productive in any ways. – 3c71 Jul 11 '15 at 14:21
  • You can write script to automate this cleanup. It's XML to seasily parseable - delete what is useless from your base language files, and then make your script rewrite other languages removing entries that are gone. – Marcin Orlowski Jul 11 '15 at 19:18
  • 1
    This is no longer the correct answer. Android Studio can handle it now. Please see Dmitry Ognyov's answer. – themichaelscott Mar 28 '18 at 00:11
  • This is still correct answer as of 2014 it was posted. And even as of 2018 it's still valid, except there are luckily other, easier ways. You seem surprised things changed in last 4 years. – Marcin Orlowski Mar 28 '18 at 14:43
  • 1
    It's an outdated answer. Noone uses adt anymore – Leo DroidCoder Jan 17 '19 at 11:42
0

This is the way that I have done to Delete a language I do not want.

1: Make a backup copy of your project.zip

2:Go to Your project folder >app>src>main>res:

In this folder, you will find all languages ​​in the form of folders

Remove the language folder that you not want For example : values-ar-rSA

back to android studio clean your project and test

Said Erraoudy
  • 1,490
  • 1
  • 13
  • 21