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

NFR: Support 'context' in Gettext (msgctxt) #12201

Closed
xerron opened this issue Sep 3, 2016 · 4 comments
Closed

NFR: Support 'context' in Gettext (msgctxt) #12201

xerron opened this issue Sep 3, 2016 · 4 comments
Labels
new feature request Planned Feature or New Feature Request

Comments

@xerron
Copy link

xerron commented Sep 3, 2016

# messages.po file (Croatian translation)

msgctxt "optionInForms"
msgid "yes"
msgstr "da"

msgctxt "confirmation"
msgid "yes"
msgstr "OK"

NFR, not affect old code if:

public string t (string $translateKey, [array $placeholders]) 

add:

public string t (string $translateKey, [array $placeholders], [string $context])

https://docs.phalconphp.com/en/latest/api/Phalcon_Translate_Adapter_Gettext.html

@sergeyklay sergeyklay added this to the 3.1.0 milestone Sep 3, 2016
@sergeyklay sergeyklay modified the milestones: 3.1.0, 3.2.0 Mar 2, 2017
@Zaszczyk
Copy link
Contributor

I already use PHP implementation, probably it will help You:

public function tWithContext($translateKey, array $placeholders = [], $context = null)
    {
        $contextString = "{$context}\004{$translateKey}";
        $translation = dcgettext('message', $contextString, LC_MESSAGES);
        if ($translation == $contextString) {
            return $this->_($translateKey, $placeholders);
        } else {
            if (count($translation) > 0) {
                $translation = $this->replacePlaceholders($translation, $placeholders);
            }
            return $translation;
        }
    }

@sergeyklay sergeyklay modified the milestones: 4.0.0, 3.2.0 Jun 17, 2017
@sergeyklay
Copy link
Contributor

Refs: zephir-lang/zephir#938

@stale stale bot added the stale Stale issue - automatically closed label Apr 16, 2018
@sergeyklay sergeyklay reopened this May 2, 2018
@stale stale bot removed the stale Stale issue - automatically closed label May 2, 2018
@phalcon phalcon deleted a comment from stale bot Dec 23, 2018
@niden
Copy link
Member

niden commented Feb 23, 2019

Closing in favor of #13855. Will revisit if the community votes for it, or in later versions.

@niden niden closed this as completed Feb 23, 2019
@scrnjakovic
Copy link
Contributor

scrnjakovic commented Feb 26, 2019

The thing is that contexts are missing in PHP's native implementation of gettext functions.

I made this for myself and decided sharing it https://github.com/scrnjakovic/php-gettext-context

Include file via loader and don't forget to hook into volt.

TIP: You can use twig extractors for Volt, as you will rarely find a good Volt extractor.

@niden niden removed this from the 4.0.0 milestone Dec 9, 2019
@niden niden added the new feature request Planned Feature or New Feature Request label Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature request Planned Feature or New Feature Request
Projects
None yet
Development

No branches or pull requests

5 participants