Comments (4)
Hi there! Sure, new ideas always welcome :-)
Okay, so let me check first that I've understood your motivation correctly (please correct any misunderstandings):
- You want to define a single dictionary by merging small parts so that each small part is relatively easier to manage.
- You want to be able to define parts in different namespaces.
- You don't want to import dictionary parts from external resources (as per the
:ja
in the `example-tconfig). - You want to define individual translation entries with a function.
On your implementation:
- There's a recursive merge fn already available in one of Tower's dependencies which you may find convenient:
(:require [taoensso.encore :as encore])
(encore/merge-deep m1 m2 ...)
- You might also find
encore/swap-in!
useful as a substitute foradd-translation!
. - The watch shouldn't be necessary in dev-mode, at least with Tower 2.1. All
t
fns will automatically recompile any dictionary changes. This may not be true of earlier versions, I don't recall off-hand.
On the general idea:
I don't think there's anything fundamentally wrong with the approach if you're comfortable with it. I may suggest avoiding the per-entry add-translation
fn though. Regular maps are portable, translator friendly, and amenable to inspection with the standard seq API when debugging, etc.
I might suggest a middle ground by defining, say, a ns-level map of however-many translations, and then doing a swap-in!
merge-deep
for the whole lot at once. That way you've still got the benefit of working with plain data, but you can keep it & merge it wherever you find most convenient.
One sharp edge to be aware of: when you're in production, you'll need to make sure that all your dictionary modifiers have executed before the first call to any t
fn. The first call will cache the dictionary's value forever. Does that make sense?
from tower.
It does, thank vou very much!
Oh, and good catch on the merge-deep
function!
On Thu, Apr 3, 2014 at 7:09 AM, Peter Taoussanis
[email protected]:
Hi there! Sure, new ideas always welcome :-)
Okay, so let me check first that I've understood your motivation correctly
(please correct any misunderstandings):
- You want to define a single dictionary by merging small parts so
that each small part is relatively easier to manage.- You want to be able to define parts in different namespaces.
- You don't want to import dictionary parts from external resources
(as per the :ja in the `example-tconfig).- You want to define individual translation entries with a function.
On your implementation:
- There's a recursive merge fn already available in one of Tower's
dependencies which you may find convenient:(:require [taoensso.encore :as encore])(encore/merge-deep m1 m2 ...)
- You might also find encore/swap-in! useful as a substitute for
add-translation!.- The watch shouldn't be necessary in dev-mode, at least with Tower
2.1. All t fns will automatically recompile any dictionary changes.
This may not be true of earlier versions, I don't recall off-hand.On the general idea:
I don't think there's anything fundamentally wrong with the approach if
you're comfortable with it. I may suggest avoiding the per-entry
add-translation fn though. Regular maps are portable, translator
friendly, and amenable to inspection with the standard seq API when
debugging, etc.I might suggest a middle ground by defining, say, a ns-level map of
however-many translations, and then doing a swap-in! merge-deep for the
whole lot at once. That way you've still got the benefit of working with
plain data, but you can keep it & merge it wherever you find most
convenient.One sharp edge to be aware of: when you're in production, you'll need to
make sure that all your dictionary modifiers have executed before the
first call to any t fn. The first call will cache the dictionary's value
forever. Does that make sense?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/41#issuecomment-39438949
.
from tower.
Why are the given dictionaries paths loaded with io/resource?
With a simple slurp I could load the EDN file wherever it is. But by using io/resource, I need to place my files in the resources directory.
from tower.
Resources are more flexible: they're packaged up with your application and can be accessed via the application jar without a concrete file being present and w/o needing to manually distribute your slurps.
from tower.
Related Issues (20)
- make-t fails for a dictionary containing language tag :id HOT 6
- What is correct way to specify deeply nested translation path? HOT 10
- Compilation of tower.cljs fails with ClojureScript 0.0-2913 HOT 16
- Temp: testing markdown
- AssertionError from make-t when map with :missing is loaded from external resource HOT 3
- Maximum text size (hint for translator) and entity property texts HOT 3
- Invalid locale exception when passing arguments to translation in sw locale HOT 6
- Script support for languages HOT 4
- Tower 3.1.0-beta3 with ClojureScript: IllegalArgumentException with tower/dict-compile* HOT 6
- timbre/logp not found HOT 4
- Best way to make dynamic paths HOT 2
- Wrong Swedish currency output HOT 2
- using figwheel in translation HOT 3
- Dependency problem HOT 2
- Formatting time and timezone
- Warn about `dev-mode?` in readme and changelog? HOT 1
- encore.cljs: contains? not supported on type: clojure.lang.PersistentList HOT 2
- Assert failed: Invalid tconfig key: :dictionary HOT 1
- Customizable markdown
- Invalid locale exception with numeric region code
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 tower.