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

Handling empty msgstr case #9

Closed
us3r64 opened this issue Aug 29, 2017 · 2 comments
Closed

Handling empty msgstr case #9

us3r64 opened this issue Aug 29, 2017 · 2 comments
Assignees

Comments

@us3r64
Copy link

us3r64 commented Aug 29, 2017

If msgstr is empty msgstr "" shouldn't the original string, untranslated version, be returned?

After some tests this looks for me the right checks to handle the empty case

func (t *translation) get() string {
    // Look for translation index 0
    if _, ok := t.trs[0]; ok {
        // handle empty msgstr
        if len(t.trs[0]) == 0 {
            return t.id
        }
        return t.trs[0]
    }

    // Return unstranlated id by default
    return t.id
}

func (t *translation) getN(n int) string {
    // Look for translation index
    if _, ok := t.trs[n]; ok {
        // handle empty msgstr
        if len(t.trs[n]) == 0 {
            if len(t.pluralID) == 0 {
                return t.id
            }
            return t.pluralID
        }
        return t.trs[n]
    }

    // Return unstranlated plural by default
    return t.pluralID
}

@leonelquinteros
Copy link
Owner

You're right, as defined in https://www.gnu.org/software/gettext/manual/html_node/Untranslated-Entries.html empty translation strings should be handled as "untranslated".

I've pushed a fix for this and will do a small release for it.

Thanks for reporting!

@us3r64
Copy link
Author

us3r64 commented Sep 1, 2017

Hi,

The issue is not fixed 100%.

For GetD you do GetND with plural set to 1 but pluralID doesn't get set.

So for empty msgstr you still get "", make sense?

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

No branches or pull requests

2 participants