Comments (10)
Oh, may be I misinterpreted docs: namespace part can contain dot, but name part cannot. Right? If so, excuse me for the noise.
from tower.
Hi Ruslan,
Namespace part can definitely contain a dot. The name part containing a dot is contentious, I think: it was historically disallowed by the spec - but I know that at least ClojureScript has started officially using it in cases like js/foo.bar
, etc.
Tower isn't too restrictive in what it accepts, but I'd suggest the :a.b/c
form (dots in namespace okay, no dots after namespace) just to be safe. :a/b/c
is definitely wrong.
Hope that helps?
from tower.
Yes, thank you!
from tower.
On this subject, I couldn't get the translation path to resolve in ClojureScript unless I used the dot style. The slash style was never able to compile...
Caused by: clojure.lang.ExceptionInfo: Invalid token: :forms/new-user/title {:type :reader-exception, :line 12, :column 80, :file "[...]/client/components/user/state.cljs"}
at clojure.core$ex_info.invoke(core.clj:4593)
at clojure.tools.reader.reader_types$reader_error.doInvoke(reader_types.clj:330)
at clojure.lang.RestFn.invoke(RestFn.java:439)
at clojure.tools.reader$read_keyword.invoke(reader.clj:354)
at clojure.tools.reader$read_STAR_.invoke(reader.clj:878)
at clojure.tools.reader$read_delimited.invoke(reader.clj:189)
at clojure.tools.reader$read_list.invoke(reader.clj:202)
at clojure.tools.reader$read_STAR_.invoke(reader.clj:878)
at clojure.tools.reader$read_delimited.invoke(reader.clj:189)
at clojure.tools.reader$read_map.invoke(reader.clj:236)
at clojure.tools.reader$read_STAR_.invoke(reader.clj:878)
at clojure.tools.reader$read_delimited.invoke(reader.clj:189)
at clojure.tools.reader$read_map.invoke(reader.clj:236)
at clojure.tools.reader$read_STAR_.invoke(reader.clj:878)
at clojure.tools.reader$read_delimited.invoke(reader.clj:189)
at clojure.tools.reader$read_list.invoke(reader.clj:202)
at clojure.tools.reader$read_STAR_.invoke(reader.clj:878)
at clojure.tools.reader$read.invoke(reader.clj:927)
at cljs.analyzer$forms_seq_STAR_$forms_seq___2134$fn__2135$fn__2136.invoke(analyzer.cljc:2040)
at cljs.analyzer$forms_seq_STAR_$forms_seq___2134$fn__2135.invoke(analyzer.cljc:2034)
at clojure.lang.LazySeq.sval(LazySeq.java:40)
at clojure.lang.LazySeq.seq(LazySeq.java:49)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:674)
at clojure.core$next__4112.invoke(core.clj:64)
at cljs.analyzer$analyze_file$fn__2173.invoke(analyzer.cljc:2235)
at cljs.analyzer$analyze_file.invoke(analyzer.cljc:2227)
at cljs.analyzer$analyze_deps.invoke(analyzer.cljc:1291)
at cljs.analyzer$eval1872$fn__1874.invoke(analyzer.cljc:1545)
at clojure.lang.MultiFn.invoke(MultiFn.java:251)
at cljs.analyzer$analyze_seq.invoke(analyzer.cljc:1900)
... 40 more
That exact path was fine when I changed it to :forms.new-user.title
I'm using 3.1.0-beta3
from tower.
:forms/new-user/title
Please note that this is not a valid keyword on any platform. It may work in Clojure by accident (not sure), but it's definitely malformed by the spec. I would strongly recommend against this form even if it seems to work in some cases. Any support is accidental and may break at any time.
from tower.
Perhaps I am confused... The README in the Translation section says to use it in that way? https://github.com/ptaoussanis/tower/blob/master/README.md#translation IE:
(t :en :example/inline-markdown)
from tower.
Ah! I see now, after looking through the source: https://github.com/ptaoussanis/encore/blob/master/src/taoensso/encore.cljx#L576
It explodes it and uses a get-in to find the translation.
from tower.
Perhaps I am confused... The README in the Translation section says to use it in that way? https://github.com/ptaoussanis/tower/blob/master/README.md#translation IE:
(t :en :example/inline-markdown)
Note that :foo/bar is a valid keyword but :foo/bar/baz
is not: a keyword can have at most one /
(which separates the "namespace" and "name" parts).
As far as Clojure/Script is concerned (i.e. nothing to do with Tower specifically):
:foo
is a valid keyword with "foo" name and no namespace.
:foo/bar
is a valid keyword with "bar" name and "foo" namespace.
:foo.bar/baz"
is a valid keyword with "baz" name and "foo.bar" namespace.
:foo/bar/baz
is invalid (malformed) since it has more than one /
.
:foo.bar.baz
is valid with "foo.bar.baz" name and no namespace.
Tower happens to ignore slashes since it doesn't care about the technical distinction between "name" and "namespace", so :foo.bar
and :foo/bar
will pick up the same translation key - but you may find that malformed keywordss won't even get through the Clojure/Script compiler - or may otherwise cause issues now or down the line.
Simplest thing to do if you don't want to think about this too much - just use .
's as your only separators - never any slashes.
Does that help / make sense?
from tower.
Yes, it does – thanks a lot for the clarification! 😄
from tower.
@ptaoussanis your last comment would be a great thing to add in the tempura documentation. Just spent a while trying to understand why I couldn't dig very deep into my dictionary. Maybe adding an example of a key that is three or four levels deep?
from tower.
Related Issues (20)
- make-t fails for a dictionary containing language tag :id HOT 6
- 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.