Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return untranslated string instead of undefined in runtime translation #654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brigadier
Copy link
Contributor

When string is not found in dictionaries it is better to return untranslated string than undefined atom.

When string is not found in dictionaries it is better to return untranslated string than `undefined` atom.
true ->
fun(String) ->
case ?MODULE:lookup(Pid, String, Locale) of
undefined -> String;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brigadier I'm not quite sure if in general it's not better to stick with undefined, as I think that from the point of using the interface it would maybe be helpful for someone to check if a translation was found or not. This change would also break backward compatibility. We also had the need for that and implemented a wrapper around the lookup/3 method:

handle_translation(TextToTranslate) ->
    TPid = boss_web:translator_pid(app_config:app_name()),
    case boss_translator:lookup(TPid, TextToTranslate, <locale>) of
        undefined ->
            TextToTranslate;
        Translation ->
            Translation
    end.

Maybe it would be better to introduce some additional functions for example fun_for_<foo>/2 and for lookup_<foo>/3 which could provide this behaviour and also keep backward compatibility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants