Closed sandrodz closed 6 years ago
First gettext can parse pug files (I use python language, maybe now there is a pug option right in the settings), so you can use right in templates:
p=_("Hello world")
I would recommend this approach because it makes templates easiest to work with and avoid passing a lot of data from the controller.
If you have some common and dynamic texts, use the share method:
$pug->share(array(
'language' => 'en',
'title' => 'My website'
));
works great :) I use both methods yes.
btw, it needs textdomain otherwise it doesn't work in php. e.g. p=__("Hello world","domain")
Is it possible to add domain during compilation? just to have pug files cleaner.
Just add this on the top of the template or in a layout/include:
- textdomain("domain")
header
p=_("Hello world")
| Pug template content...
Thanks!
@kylekatarnls last question I promise ^_^ do you know any more elegant way of writing these?
#{__()}
seems terrible.
Not realy better. You can do this:
| 120
=_(...)
=" "
=_(...)
@kylekatarnls
I get this error: Undefined variable: textdomain on line 1, offset 1
Hi, I suspect gettext to not be installed and enabled, can you check it with phpinfo()
?
I have the module:
I'm using: 'expressionLanguage' => 'js'
Authors are just credits of installed modules. They can be installed without being enabled.
The needed setting is:
Also be sure, this is the same PHP program (run - phpinfo()
directly from the pug template to be sure), you can have Apache and CLI with different settings, and potentially different versions of PHP installed.
Yes you were right. Updated my docker containers with gettext module: https://github.com/wearede/DevCeption/commit/6f72470ca022c4cb3dc8e540842a350555f7c6f4
Great!
Hi, I'm still having issues with this.
It only works if I add text domain inside the __
calls e.g.
Without text domain strings are not translated.
I have:
- textdomain(txtdomain)¬
at the beginning of the base pug file.
Hi,
The gettext function take exactly 1 argument, no more. And this come with - textdomain()
function separated.
Can I see your __()
function definition because I cannot understand how it can be gettext and support 2 arguments.
It is a get text wrapper for WordPress: https://codex.wordpress.org/I18n_for_WordPress_Developers
Sorry for confusion!
I think it's a "feature" of this plugin, see the documentation (and also the file source https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/l10n.php#L121):
(string) (optional) Domain to retrieve the translated text
Default: 'default'
What I understand is: if you don't specify, the domain as second argument, it will be replaced by the string "default"
. So textdomain(txtdomain)
is never taken into account. That's seems a bit dummy to me according to gettext standard usage but it can be some easier for small app with only one text domain, so you just have to name this domain "default".
You could do your own wrapper-wrapper:
function ___($text, $domain = null) {
return __($text, $domain === null ? textdomain() : $domain);
}
function __e($text, $domain = null) {
return _e($text, $domain === null ? textdomain() : $domain);
}
I need to run all strings in plain language in a php localisation function.
e.g.
__( 'some string', 'mytheme' )
or_e( 'some string', 'mytheme' )
(shortcuts to php gettext)What is the best way to achieve this?
I could build a data array and pre populate it with strings and pass it to pug:
and than interpolate
string1
inside pug.But surely there is a better way :)