You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Correia <ca...@celfocus.com> on 2017/04/26 21:23:40 UTC

Sling JSON i18n

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.

Re: Sling JSON i18n

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Thu, Apr 27, 2017 at 1:01 PM, Correia
<ca...@celfocus.com> wrote:
> ...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

Re: Sling JSON i18n

Posted by Correia <ca...@celfocus.com>.
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.

Re: Sling JSON i18n

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, Apr 27, 2017 at 12:14 PM, Correia
<ca...@celfocus.com> wrote:
> ...What I wanted to do is having a pure JSON file like:
> {
>     "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

Re: Sling JSON i18n

Posted by Correia <ca...@celfocus.com>.
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.

Re: Sling JSON i18n

Posted by Chris Millar <ch...@millr.org>.
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.

> On Apr 26, 2017, at 3:23 PM, Correia <ca...@celfocus.com> wrote:
> 
> 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.

Re: Sling pipes release

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Apr 28, 2017 at 12:28 AM, Correia
<ca...@celfocus.com> wrote:
> ...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

Re: Sling pipes release

Posted by Correia <ca...@celfocus.com>.
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.

Re: Sling pipes release

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 27.04.2017, at 06:12, Correia <ca...@celfocus.com> wrote:
> 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.

Cheers,
Alex

Re: Sling pipes release

Posted by Correia <ca...@celfocus.com>.
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.

Re: Sling pipes release

Posted by Robert Munteanu <ro...@apache.org>.
On Fri, 2017-04-28 at 09:37 +0000, Nicolas Peltier wrote:
> Hi,
> 
> gentle bump
> 
> In the meanwhile, SLING-6538 and SLING-6801 can be added too :-)

All patches applied. We still need to do some tweaking for SLING-6800.
Once that's done I will start the release process.

Robert
> 
> > On 27 Apr 2017, at 15:42, Nicolas Peltier <np...@adobe.com>
> > wrote:
> > 
> > It’s done :-) 
> > 
> > > On 27 Apr 2017, at 15:39, Robert Munteanu <ro...@apache.org>
> > > wrote:
> > > 
> > > Hi Nicolas,
> > > 
> > > (moving to dev@)
> > > 
> > > On Thu, 2017-04-27 at 12:16 +0000, Nicolas Peltier wrote:
> > > > Hi,
> > > > 
> > > > Is it possible to fix SLING-6800 and create a 0.0.12 release
> > > > for
> > > > sling pipes?
> > > > 
> > > > Thanks,
> > > > Nicolas
> > > 
> > > I see there's already a discussion going on in the pull request
> > > for
> > > SLING-6800 . Once that's done we can start the release vote.
> > > 
> > > Robert
> 
> 


Re: Sling pipes release

Posted by Nicolas Peltier <np...@adobe.com>.
Hi,

gentle bump

In the meanwhile, SLING-6538 and SLING-6801 can be added too :-)

> On 27 Apr 2017, at 15:42, Nicolas Peltier <np...@adobe.com> wrote:
> 
> It’s done :-) 
> 
>> On 27 Apr 2017, at 15:39, Robert Munteanu <ro...@apache.org> wrote:
>> 
>> Hi Nicolas,
>> 
>> (moving to dev@)
>> 
>> On Thu, 2017-04-27 at 12:16 +0000, Nicolas Peltier wrote:
>>> Hi,
>>> 
>>> Is it possible to fix SLING-6800 and create a 0.0.12 release for
>>> sling pipes?
>>> 
>>> Thanks,
>>> Nicolas
>> 
>> I see there's already a discussion going on in the pull request for
>> SLING-6800 . Once that's done we can start the release vote.
>> 
>> Robert
> 


Re: Sling pipes release

Posted by Nicolas Peltier <np...@adobe.com>.
It’s done :-) 

> On 27 Apr 2017, at 15:39, Robert Munteanu <ro...@apache.org> wrote:
> 
> Hi Nicolas,
> 
> (moving to dev@)
> 
> On Thu, 2017-04-27 at 12:16 +0000, Nicolas Peltier wrote:
>> Hi,
>> 
>> Is it possible to fix SLING-6800 and create a 0.0.12 release for
>> sling pipes?
>> 
>> Thanks,
>> Nicolas
> 
> I see there's already a discussion going on in the pull request for
> SLING-6800 . Once that's done we can start the release vote.
> 
> Robert


Re: Sling pipes release

Posted by Robert Munteanu <ro...@apache.org>.
Hi Nicolas,

(moving to dev@)

On Thu, 2017-04-27 at 12:16 +0000, Nicolas Peltier wrote:
> Hi,
> 
> Is it possible to fix SLING-6800 and create a 0.0.12 release for
> sling pipes?
> 
> Thanks,
> Nicolas

I see there's already a discussion going on in the pull request for
SLING-6800 . Once that's done we can start the release vote.

Robert

Sling pipes release

Posted by Nicolas Peltier <np...@adobe.com>.
Hi,

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

Thanks,
Nicolas