Repository: freedomofpress/securedrop

Issue:
error when compiling ro translations
## Description

Discovered and fixed by @kushaldas in d63f61458cfdf41e95df673e2fba92b1c704d159, just filing this as an issue so there is a clear change history

## Steps to Reproduce

1. Add `ro` (Romanian) to SecureDrop's supported languages (ref: 862860f80b9435cf5df2549f97dabe6f41182386)

2. Compile translations:

```
$ securedrop/bin/dev-shell ./i18n_tool.py --verbose translate-desktop --compile
```

## Expected Behavior

`.mo` files are created

## Actual Behavior

```
$ securedrop/bin/dev-shell ./i18n_tool.py --verbose translate-desktop --compile
Run with DOCKER_BUILD_VERBOSE=true for more information
Docker image build in progress  done !
2019-02-25 17:28:43,373 INFO <Command u'/usr/bin/msgfmt --desktop --template desktop-journalist-icon.j2.in -o desktop-journalist-icon.j2 -d .'>: starting process
2019-02-25 17:28:43,380 INFO <Command u'/usr/bin/msgfmt --desktop --template desktop-journalist-icon.j2.in -o desktop-journalist-icon.j2 -d .', pid 9>: process started
Traceback (most recent call last):
  File "./i18n_tool.py", line 372, in <module>
    sys.exit(I18NTool().main(sys.argv[1:]))
  File "./i18n_tool.py", line 366, in main
    return args.func(args)
  File "./i18n_tool.py", line 139, in translate_desktop
    _cwd=args.translations_dir)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1427, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 774, in __init__
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 792, in wait
    self.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /usr/bin/msgfmt --desktop --template desktop-journalist-icon.j2.in -o desktop-journalist-icon.j2 -d .

  STDOUT:


  STDERR:
/usr/bin/msgfmt: error while opening "r.po" for reading: No such file or directory
```

## Comments

This is due to rstrip stripping an additional character


Discussion:

Resolving patch:
diff --git a/securedrop/i18n_tool.py b/securedrop/i18n_tool.py
--- a/securedrop/i18n_tool.py
+++ b/securedrop/i18n_tool.py
@@ -40,10 +40,12 @@ class I18NTool(object):
         'fr_FR': {'name': 'French', 'desktop': 'fr', },
         'el': {'name': 'Greek', 'desktop': 'el', },
         'hi': {'name': 'Hindi', 'desktop': 'hi', },
+        'is': {'name': 'Icelandic', 'desktop': 'is', },
         'it_IT': {'name': 'Italian', 'desktop': 'it', },
         'nb_NO': {'name': 'Norwegian', 'desktop': 'nb_NO', },
         'nl': {'name': 'Dutch', 'desktop': 'nl', },
         'pt_BR': {'name': 'Portuguese, Brasil', 'desktop': 'pt_BR', },
+        'ro': {'name': 'Romanian', 'desktop': 'ro', },
         'ru': {'name': 'Russian', 'desktop': 'ru', },
         'sv': {'name': 'Swedish', 'desktop': 'sv', },
         'tr': {'name': 'Turkish', 'desktop': 'tr', },
@@ -124,7 +126,7 @@ def translate_desktop(self, args):
         if args.compile:
             pos = filter(lambda f: f.endswith('.po'),
                          os.listdir(args.translations_dir))
-            linguas = map(lambda l: l.rstrip('.po'), pos)
+            linguas = map(lambda l: l[:-3], pos)
             content = "\n".join(linguas) + "\n"
             open(join(args.translations_dir, 'LINGUAS'), 'w').write(content)
 


Test patch:
diff --git a/securedrop/tests/test_i18n_tool.py b/securedrop/tests/test_i18n_tool.py
--- a/securedrop/tests/test_i18n_tool.py
+++ b/securedrop/tests/test_i18n_tool.py
@@ -85,6 +85,21 @@ def test_translate_desktop_l10n(self, tmpdir):
             po_file)
         assert exists(po_file)
 
+        # Regression test to trigger bug introduced when adding
+        # Romanian as an accepted language.
+        locale = 'ro'
+        po_file = join(str(tmpdir), locale + ".po")
+        msginit(
+            '--no-translator',
+            '--locale', locale,
+            '--output', po_file,
+            '--input', messages_file)
+        source = 'SecureDrop Source Interfaces'
+        sed('-i', '-e',
+            '/{}/,+1s/msgstr ""/msgstr "SOURCE RO"/'.format(source),
+            po_file)
+        assert exists(po_file)
+
         #
         # Compile but do not extract+update
         #