Integration with GNU gettext

Open
#165 18 comments 0 reactions 0 assignees View on GitHub

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

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

enhancement

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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from smarty-php/smarty

All issues in smarty-php/smarty

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.