Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
ffbs-gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
darkbit
ffbs-gluon
Commits
1d7b4482
Unverified
Commit
1d7b4482
authored
8 years ago
by
Matthias Schiffer
Browse files
Options
Downloads
Patches
Plain Diff
gluon-web: add renderer._translate()
_translate() will return nil when no match is found.
parent
e70ced9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/dev/web/i18n.rst
+5
-4
5 additions, 4 deletions
docs/dev/web/i18n.rst
docs/dev/web/view.rst
+1
-1
1 addition, 1 deletion
docs/dev/web/view.rst
package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua
+8
-1
8 additions, 1 deletion
package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua
with
14 additions
and
6 deletions
docs/dev/web/i18n.rst
+
5
−
4
View file @
1d7b4482
...
...
@@ -17,10 +17,11 @@ i18n support in Gluon
---------------------
Internationalization support is available in all components (models, view and
contrllers) of *gluon-web*-based packages. Strings are translated using the *translate*
and *translatef* functions (*translate* for static strings, *translatef*
for printf-like formatted string); in views, the special tags ``<%:...%>`` can
be used to translate the contained string.
contrllers) of *gluon-web*-based packages. Strings are translated using the *translate*,
*_translate* and *translatef* functions (*translate* for static strings, *translatef*
for printf-like formatted string; *_translate* works the same as *translate*, but
will return *nil* instead of the original string when no translation is available)
. In views, the special tags ``<%:...%>`` can be used to translate the contained string.
Example from the *gluon-config-mode-geo-location* package:
...
...
This diff is collapsed.
Click to expand it.
docs/dev/web/view.rst
+
1
−
1
View file @
1d7b4482
...
...
@@ -52,4 +52,4 @@ variables and functions should always be available for the embedded Lua code:
Use ``node(unpack(request))`` to get the node for the current page.
- *pcdata* (*str*): Escapes HTML entities in the passed string.
- *urlencode* (*str*): Escapes the passed string for use in an URL.
- *translate* and *translatef*: see :doc:`i18n`
- *translate*
, *_translate*
and *translatef*: see :doc:`i18n`
This diff is collapsed.
Click to expand it.
package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua
+
8
−
1
View file @
1d7b4482
...
...
@@ -25,6 +25,7 @@ function renderer(env)
renderer
=
ctx
,
translate
=
ctx
.
translate
,
translatef
=
ctx
.
translatef
,
_translate
=
ctx
.
_translate
,
include
=
function
(
name
)
ctx
.
render
(
name
,
scope
)
end
,
...
...
@@ -79,13 +80,19 @@ function renderer(env)
return
tparser
.
load_catalog
(
lang
,
i18ndir
)
end
-- Returns a translated string, or nil if none is found
function
ctx
.
_translate
(
key
)
return
(
tparser
.
translate
(
key
))
end
-- Returns a translated string, or the original string if none is found
function
ctx
.
translate
(
key
)
return
tparser
.
translate
(
key
)
or
key
end
function
ctx
.
translatef
(
key
,
...
)
local
t
=
ctx
.
translate
(
key
)
return
t
and
t
:
format
(
...
)
return
t
:
format
(
...
)
end
return
ctx
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment