Comments (5)
@jeffharrell is there no way within Controller to access language bundle to match a key value for current locale to a dynamic object returned from DB?
Say I have a Lucene search that includes facets with stats I want to update in sparklines as pages load, and sparkline file is include. I need sparkline file to be able to iterate through list of objects in model with stat count, list of bars, and a label to dynamically build 2 - 5 of these sparklines. The counts are okay but the label needs to match a key in bundle for current locale. I cannot seem to find a way to get this to work without hard-coding templates and lose the ability to just include a dynamic sparkline file that accepts list and renders mini stats.
Example model
stats: [
{key:'mini_stats.available', style:'sparkline_bar_good', value:'35', bars:[2,4,9,7,12,10,12]},
{key:'mini_stats.sold_this_month', style:'sparkline_bar_neutral', value:'12', bars:[2,4,9,7,12,10,12]}
],
Problem is even if I include key values matching bundle properties, since bundles evaluated at build time I'm unable to dynamically build this row of sparklines with the label for each stat. I cannot seem to find a way to render this content dynamically on the page and match language bundle key.
Goal would be to have a dust template that iterates through {#stats}<sparkline code here>{/stats}
and could either evaluate the key sent from Model, or perhaps on Controller it can match keys and load proper label (i.e. Available, Sold This Mo, etc.).
Idea would be that the model includes label Available
, Sold This Mo
coming from facet filter results corresponding to counts and histograms. These are part of stats
model list. The template could then do a Map lookup in bundle to match key {@pre type="content" key="miniStats[{label}]" /}
. Since @pre
only works at build time, is there a way to access at runtime or custom helper that could accomplish this?
from makara.
@jeffharrell I built a helper to solve the issue short term and sharing on my personal page at: https://github.com/mikesparr/Kraken_Example_i18n_Helper
I'll keep my eyes open if you solve dynamically matching keys in Controller or have a better way to do this but hopefully this will help others in short term. Feel free to share, take, etc.
from makara.
We're moving away from build-time localization of templates, so this will be moot in the new design.
from makara.
What will be the new design without build-time localization?
from makara.
Templates will include @pre
(deprecated), @message
(backward-compatible) or @formatMessage
(via formatjs.io project) helpers, and you can plug in a language bundle resolver that will supply bundles of strings. At the moment, that means loading a language-specific <script>
tag with the actual strings, in addition to the javascript bundle of your app.
from makara.
Related Issues (20)
- multi
- Plan for makara deprecation HOT 6
- Add support for formatPath in Bundalo.
- dust helpers documentation is wrong HOT 1
- Express app stops responding if there are too many partial includes HOT 6
- specialization seems to be broken HOT 24
- Makara doesn't look up localised templates HOT 3
- Problem with format path HOT 3
- Makara 2 and Dust @provide helper HOT 3
- Makara 2 with locale from cookie is not localizing templates HOT 1
- Upgrading makara: client side HOT 9
- Locale specific templates HOT 4
- Build task on windows fails due to OS path separator issue HOT 4
- is there a concept of fallback at the level of the Country HOT 3
- Question: what are the various ways to manually set the expressjs-res's locale HOT 4
- I can't pass the enableMetadata parameter HOT 2
- Don't load req.locale HOT 1
- Update the bundalo to 1.x to remove dependency from dustjs-linkedin HOT 1
- is makara only for dustjs template engine?
- Update bundalo for security issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from makara.