Integration with GNU gettext
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- php
- Domain
- internationalization, localization
Research direction
No file or test is named. Start by reading issue 164 and the current block-plugin and preprocessor implementation, then compare the proposed function, block, and inline syntaxes with gettext and xgettext constraints. Done means the design is agreed and a workable implementation path is identified for plural, context, domain, encoding, and parameter substitution.
Written by the indexing model from the issue text.
Description
I think Smarty would beneficiate from a well designed gettext plugin. But to do this, I think we should discuss about what "well designed" mean for a gettext plugin.
Specs:
- Plural with count
- Context
- Domain
- Able to mix HTML contexts (url (urlencode), html (htmlencode))
- Allow translators to swap parameters (Typically using %2s, %1s)
I'll present the ideas using the following, typical example:
I pushed <a href="%s">%s on %s</a>!
First things first I think we can't use a |trans modifier, as modifier parameters can't be modified, and, at least capitalizing a parameter to be given to gettext may be usefull.
So we may use either a function:
{trans string="string"}
Or a block:
{trans}string{/trans}
The example using the function may give:
{trans string="I pushed <a href="%s">%s on %s</a>!" 1=$url|urlencode 2=$what|htmlencode 3=$where|htmlencode}
And with a block:
{trans 1=$url|urlencode 2=$what|htmlencode 3=$where|htmlencode}I pushed <a href="%s">%s on %s</a>!{/trans}
That's more or less the same but some things to note here:
- 1, 2, 3 are ugly, we better use positional parameter (see https://github.com/smarty-php/smarty/issues/164)
- Positional parameter are better but still not that readable about what parameter maps to which place
Just for the record, a version with positional parameters and a context:
{trans $url|urlencode $what|htmlencode $where|htmlencode}I pushed <a href="%s">%s on %s</a>!{/trans}
To enhance readability one may though of:
{trans}I pushed <a href="{$url|urlencode}">{$what|htmlencode} on {$where|htmlencode}</a>!{/trans}
That's clearly more readable, sadly it won't work with current implementation of block plugins as content is processed (strings are replaced) before being given to the block.
This may be doable using a preprocessor plugin rewriting the "inplace syntax" to a "parametrized syntax".
Obviously this last syntax need a specialized xgettext that'll replace {....} in strings by %1s, %2s, etc...: there's NO way we get {$url|urlencode} in po files (Also think that the translation may be used by other languages, so %1s is cool (supported by C, Java, whatever...)
I'm waiting for feedback on those ideas, while trying to implement the preprocessor.
- Dominant language
- PHP
- Stars
- 2.3k
- Forks
- 709
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from smarty-php/smarty
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
smarty-php/smarty#1208 · 1 comment ·
-
major
Difficulty 4/5 3-5 days Newbie friendliness 30/100
smarty-php/smarty#1199 · 1 reaction ·
-
Harden Security mode Openmajor
Difficulty 5/5 Over a week Newbie friendliness 35/100
smarty-php/smarty#1197 · 1 reaction ·
-
Smarty 5 regression: Template function `{call}` variables leak into caller scope under `extends:` Open
Difficulty 3/5 1-2 days Newbie friendliness 64/100
smarty-php/smarty#1196 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
smarty-php/smarty#1188 · 3 comments ·
All issues in smarty-php/smarty
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-api#45 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
phingofficial/phing#2025 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
silverstripe/developer-docs#911 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100