Discussion:
Sling JSON i18n
Correia
2017-04-26 21:23:40 UTC
Permalink
Hi all,

I'm trying to use the Internationalization Support based inJSON as described
in Sling example:
https://sling.apache.org/documentation/bundles/internationalization-support-i18n.html

I'm having trouble creating the JSON. Can anyone provide an example?

My working attenpt:
{
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": ["mix:language"],
"jcr:language": "en",
"hello": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "Hello"
},
"hello2": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "Hello 2"
}
}

But Î want to use as key:value.

Using the page example should be something like:
{
"jcr:primaryType": "nt:file",
"jcr:mixinTypes": "[mix:language]",
"jcr:language": "en",
"jcr:content": {
"jcr:primaryType": "nt:resource",
"jcr:data": {
"hello": "Hello",
"hello2": "Hello 2"
}
}
}

Issues:
1) type "nt:file" dont allow me to define jcr:language ( No matching
property definition: jcr:language = en)
2) Missing some defenition in jcr:data (No matching property definition:
jcr:data)

PS: I'm using pure Sling. No AEM nor CQ.

Thanks,
Carlos Correia



--
View this message in context: http://apache-sling.73963.n3.nabble.com/Sling-JSON-i18n-tp4072998.html
Sent from the Sling - Users mailing list archive at Nabble.com.
Chris Millar
2017-04-27 08:26:58 UTC
Permalink
Have a look at: https://github.com/auniverseaway/slick-2/tree/master/ui.apps/src/main/resources/jcr_root/libs/languages

I can verify this works on pure Sling 8.

Let me know if you have any additional questions.
Post by Correia
Hi all,
I'm trying to use the Internationalization Support based inJSON as described
https://sling.apache.org/documentation/bundles/internationalization-support-i18n.html
I'm having trouble creating the JSON. Can anyone provide an example?
{
"jcr:primaryType": "nt:folder",
"jcr:mixinTypes": ["mix:language"],
"jcr:language": "en",
"hello": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "Hello"
},
"hello2": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "Hello 2"
}
}
But Î want to use as key:value.
{
"jcr:primaryType": "nt:file",
"jcr:mixinTypes": "[mix:language]",
"jcr:language": "en",
"jcr:content": {
"jcr:primaryType": "nt:resource",
"jcr:data": {
"hello": "Hello",
"hello2": "Hello 2"
}
}
}
1) type "nt:file" dont allow me to define jcr:language ( No matching
property definition: jcr:language = en)
jcr:data)
PS: I'm using pure Sling. No AEM nor CQ.
Thanks,
Carlos Correia
--
View this message in context: http://apache-sling.73963.n3.nabble.com/Sling-JSON-i18n-tp4072998.html
Sent from the Sling - Users mailing list archive at Nabble.com.
Correia
2017-04-27 10:14:12 UTC
Permalink
Yes, that example is similar to the one I have working.

What I wanted to do is having a pure JSON file like:
{
"hello": "Hello",
"hello2": "Hello 2"
}

Is this possible?

Follow up question...
With the suggested example I can use slightly annotation to get the label
${'hello' @i18n}.
How can I use i18n in javascript?



--
View this message in context: http://apache-sling.73963.n3.nabble.com/Sling-JSON-i18n-tp4072998p4073009.html
Sent from the Sling - Users mailing list archive at Nabble.com.
Bertrand Delacretaz
2017-04-27 10:33:21 UTC
Permalink
On Thu, Apr 27, 2017 at 12:14 PM, Correia
Post by Correia
{
"hello": "Hello",
"hello2": "Hello 2"
}
Is this possible...
Yes, as described in the docs.

The corresponding test is JcrResourceBundleTest.test_json_dictionary()
[1], it's not too readable as the json is created inline but should
provide the information that you're looking for.

-Bertrand

[1] https://github.com/apache/sling/blob/trunk/bundles/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
Correia
2017-04-27 11:01:59 UTC
Permalink
Thanks for the help.
I had already readed that documentation, but my problem is how I build my
JSON file.
I'm importing the files to the JCR repository via maven and i'm using JSON
instead of XML.

My question is how to build the JSON file under libs/languages.



--
View this message in context: http://apache-sling.73963.n3.nabble.com/Sling-JSON-i18n-tp4072998p4073012.html
Sent from the Sling - Users mailing list archive at Nabble.com.
Bertrand Delacretaz
2017-04-27 12:11:14 UTC
Permalink
Hi,

On Thu, Apr 27, 2017 at 1:01 PM, Correia
...I'm importing the files to the JCR repository via maven and i'm using JSON
instead of XML...
Ah ok got it, your problem is how to provide those json files as
initial content in your source code, without them being interpreted by
the initial content loading mechanism.

https://sling.apache.org/documentation/bundles/content-loading-jcr-contentloader.html
should help for that, if you use the "ignoreImportProviders=json"
directive in your bundle's Sling-Initial-Content header the json files
should appear as is in the content repository.

The contrib/jcr/js/nodetypes module has an example.

Let us know if that works for you!

-Bertrand
Nicolas Peltier
2017-04-27 12:16:34 UTC
Permalink
Hi,

Is it possible to fix SLING-6800 and create a 0.0.12 release for sling pipes?

Thanks,
Nicolas
Correia
2017-04-27 13:12:07 UTC
Permalink
Not getting there yet :p

Let me reformulate my question...

I'm trying to use the Internationalization Support as the example in Sling
documentation:
https://sling.apache.org/documentation/bundles/internationalization-support-i18n.html

I'm using JSON-file based

As the example describe...
/libs/languages
+-- english.json (nt:file, mix:language)
| +-- jcr:language = en
| +-- jcr:content (nt:resource)
| + jcr:data (containing the actual JSON file)
+-- deutsch.json (nt:file, mix:language)
+-- jcr:language = de
+-- jcr:content (nt:resource)
+ jcr:data (containing the actual JSON file)

I want to have two JSON files.

english.json (with node description)
{
"jcr:primaryType": "nt:file",
"jcr:mixinTypes": "[mix:language]",
"jcr:language": "en",
"jcr:content": {
"jcr:primaryType": "nt:resource",
"jcr:data": {
}
}
}

en.json (with i18n key:value)
{
"hello": "Hello",
...
}

How do I add my second JSON file to the jcr:data on the first file??



--
View this message in context: http://apache-sling.73963.n3.nabble.com/Sling-JSON-i18n-tp4072998p4073026.html
Sent from the Sling - Users mailing list archive at Nabble.com.
Alexander Klimetschek
2017-04-27 21:41:57 UTC
Permalink
Post by Correia
How do I add my second JSON file to the jcr:data on the first file??
The answer to that question must lie in the sling initial content loader mechanism, how it can incorporate binary files (i.e. the second en.json that should end up as-is as nt:file in the repository). It probably sees all json files as descriptor files and tries to read them as jcr content.

Using "ignoreImportProviders=json" won't help, as then the english.json would no longer be seen as descriptor file either.

You could turn the english.json into the xml descriptor format, and use "ignoreImportProviders=json"… that might not be perfect if you prefer the json descriptor format I guess.

Note I am not very familiar with the content loader mechanism and if there is a better way.

Chee
Correia
2017-04-27 22:28:49 UTC
Permalink
Thanks everyone for the help.

I really don't understand how it's supposed to work the example discribed in
Sling Internationalization page.

The "ignoreImportProviders=json" is not a solution because I use JSON for
all my content.

I will keep my working attempt described in first post for now.
It works great in HTML with Sightly annotation ${key @i18n}.
My problem is how to read it in Javascript...

Best Regards.



--
View this message in context: http://apache-sling.73963.n3.nabble.com/Sling-JSON-i18n-tp4072998p4073049.html
Sent from the Sling - Users mailing list archive at Nabble.com.
Bertrand Delacretaz
2017-04-28 07:42:59 UTC
Permalink
On Fri, Apr 28, 2017 at 12:28 AM, Correia
...The "ignoreImportProviders=json" is not a solution because I use JSON for
all my content...
That option is per path, so I suppose if you isolate those .json files
in a specific path that should work - but maybe that prevents you from
creating the structure that the i18n bundle needs?

Worst case, using a JCR SystemView XML file should work but maybe
that's inconvenient to generate and edit.

-Bertrand

Loading...