How to translate custom apps?

Hi there,

sorry to post, but i can’t find other post on how to translate a custom app. I got infos at:

https://frappe.github.io/frappe/user/en/guides/basics/translations

but can’t figure out how to it work.

Should I add translates/[lang].csv into the custom app?

Thx in advance

1 Like

You need to export the untranslated text first, make of copy of it and replace the text with translated text and import it back into the system.

Just follow these steps:

  1. To find untranslated strings, run bench get-untranslated [lang] [path]
  2. Add the translated strings in another file in the same order
  3. run bench update-translations [lang] [path of untranslated strings] [path of translated strings]

Let us know if you get any errors.

4 Likes

@KanchanChauhan thanks for the hint, it’s not clear what the [path] is referred to, can you post some examples?

[path] would be path of file like /Users/xyz/Documents/2016-06-17

Sorry i’m not getting you …let me explain …

I’ve a custom app and i’d like to translate from english to italian:

DocType name
DocType field name and option for Select if present

How to do that?

Thx in advance

getting an error:

bench get-untranslated it /home/frappe/frappe-bench/apps/myapp/myapp/myapp/doctype/cash_ward_refuse/cash_ward_refuse.py
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/translate.py", line 50, in get_untranslated
    frappe.translate.get_untranslated(lang, untranslated_file, get_all=all)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 576, in get_untranslated
    messages.extend(get_messages_for_app(app))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 300, in get_messages_for_app
    messages.extend(get_messages_from_custom_fields(app_name=app))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 407, in get_messages_from_custom_fields
    if cf['fieldtype'] == 'Selection' and cf.get('options'):
KeyError: u'fieldtype'

Hi,

Did you get any solution, facing same issue, want to translate custom app to other language? It may not be a custom translation, google translation would also work. Any quick fix?

Actually I’m using custom translations …check for translation l’installazione not search bar

I have similar issues.
I only want to translate the strings of my custom app. Not other frappe strings…
If i do bench get-untranslated I do get all the untranslated stings.
I can not see an --app option for this command?!

How do I make this app specific?!

Thank you

Its not supported to translate a certain app,
so you can do the following:

bench get-untranslated
bench update-translations [lang] [source-path] [source-path] 

You see above I used the same file for translation,
after this you will find a translations file in each app and you can translate the app you need.

Warning: this could mess up Erpnext and Frappe translations so either take a backup of all apps translation files, or translate locally.

Please Help me to understand this…
I run

bench get-untranslated ./ToBeTranslated

I get 420 missing translations and an accordingly long file.
I only want to translate some of those Strings for my app.
So when using the ToBeTranslated File as first [source-path] , how does the second `[source-path] has to look like when running

bench update-translations [lang] [source-path] [source-path] 

With everything I tried so far, I got the csv file without any translations.
That also would be fine, If I knew that I can translate in this csv without having to worry that it will be overridden as soon as I get more strings…
Also now I only get the strings that should be translated that origninate from a file in my .csv file.
No more do I see any strings that come from DocTypes…
What am I doing wrong?

Thank you

According to Translations, “Add the translated strings in another file in the same order”.

However, when I tried it, I got:

(env) frappe@b33f2bd70900:/workspace/development/frappe-bench/sites$ bench update-translations id untranslated.csv id.csv
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 99, in <module>
    main()
  File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/workspace/development/frappe-bench/env/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 26, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/commands/translate.py", line 68, in update_translations
    frappe.translate.update_translations(lang, untranslated_file, translated_file)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/translate.py", line 668, in update_translations
    write_translations_file(app, lang, full_dict)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/translate.py", line 703, in write_translations_file
    app_messages, full_dict or get_full_dict(lang))
  File "/workspace/development/frappe-bench/apps/frappe/frappe/translate.py", line 592, in write_csv_file
    for p, m in app_messages:

When I tried to debug write_csv_file(), app_messages structure is like:

...
('apps/frappe/frappe/templates/emails/download_data.html', ' to your browser', None, 9)
('DocType: About Us Settings', '"Company History"')
('apps/frappe/frappe/core/doctype/data_export/exporter.py', '"Parent" signifies the parent table in which this row must be added', None, 134)
...

so each row is inconsistent, usually it is a tuple with 4 elements instead of 2, and sometimes it is 2 elements.

Reported bug to: bench update-translations throws error: ValueError: not enough values to unpack (expected 4, got 2) · Issue #11429 · frappe/frappe · GitHub

1 Like