Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Shorter shotcut for a gettext helper #271

Closed
wants to merge 2 commits into from

3 participants

@lasarux

Signature is now ok. Thanks for the reply!

Pedro Gracia added some commits
@larzconwell

I'll merge this, but why is it just called 't'? We should think of a better name, because that's kinda confusing and doesn't explain what it is. Also you'll need to create a entry in docs/5-templates.md

Also sorry for the late response.

@lasarux

't' is for 'translate' and I would like to avoid confusion with '_', that is a shortcut for gettext(). 'translate' is a long word and it's a bit hard to write it again and again... and again... in templates. Is this fine for you?

@larzconwell larzconwell commented on the diff
lib/template/helpers/index.js
@@ -240,3 +240,11 @@ exports.truncateHTML = {
//altName: 'truncate_HTML',
action: utils.string.truncateHTML
};
+
+// Simple implementation to use gettext into templates
+exports.t = {
+ name: 't',
+ action: function(key, opts, locale) {
+ return i18n.getText(key, opts || {}, locale);

This will need to be utils.i18n.getText not i18n.getText

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@larzconwell

So I've thought about it, and I don't think we should merge it, we already give users access to getText via geddy.i18n.getText and geddy.utils.i18n.getText. Also users can create their own helpers. Just create a directory at app/helpers(Recently this was added to the generators) then you can create your own helpers to use.

Here's how a helper would look for your translate method: app/helpers/translate.js

exports.t = function (key, opts, locale) {
  return geddy.i18n.getText(key, opts || {}, locale);
};

Then you can use your t function like normal.

@mde
Owner

Thanks very much for the effort here, in any case. We really appreciate every effort to make Geddy better.

@larzconwell

+1 Definitely, thanks a bunch @lasarux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 23, 2012
  1. Simple i18n helper

    Pedro Gracia authored
Commits on Nov 24, 2012
  1. - better shortcut to use gettext in helpers

    Pedro Gracia authored
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 0 deletions.
  1. +8 −0 lib/template/helpers/index.js
View
8 lib/template/helpers/index.js
@@ -240,3 +240,11 @@ exports.truncateHTML = {
//altName: 'truncate_HTML',
action: utils.string.truncateHTML
};
+
+// Simple implementation to use gettext into templates
+exports.t = {
+ name: 't',
+ action: function(key, opts, locale) {
+ return i18n.getText(key, opts || {}, locale);

This will need to be utils.i18n.getText not i18n.getText

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+};
Something went wrong with that request. Please try again.