Hi Daniel,

On 28.05.2018 19:42, Daniel Klco wrote:
> Another thing to keep in mind is caching. If you want to make your
> application scale, you will need to be able to cache the content rather
> than building every response dynamically. You can either use sling
> selectors to load the correct i18n dictionary or create a language root and
> create one page per translation of the content.
Thanks for the suggestion. Caching is not on my radar right now but it
will. My plan is to keep all the translations for a page / piece of
content into a single json file ( second option in sing i18n page) .
Those pages will not see a lot of hits initially so I'm focusing on
making it work and then making it work fast :). I don't fully understand
the selectors use in this case. I put that on me being a noob in Sling :).
>
> I'd recommend the language root option as it's easier to manage the content
> than updating an i18n dictionary and you can cache each page separately
> using Dispatcher or mod_cache.
I think I understand but not sure since I don't know what do you mean by
a language root or Dispatcher? I'm sure it's an issue with aligning our
vocabulary.

I'll focus on rendering the page first. I will give it a try with Sling
Models as Oliver suggested. When I have that I may know more about when
I will have to look into caching. For sure I will open the discussion
again and ask for your input :).

/Eugen

> -Dan
>
>
> On Mon, May 28, 2018, 11:13 AM Oliver Lietz <apa...@oliverlietz.de> wrote:
>
>> On Monday 28 May 2018 11:50:25 Ioan Eugen Stan wrote:
>>> Score 1 for me 99 for Sling.
>>>
>>> I found out how to use resources in sling templates with thymeleaf.
>>>
>>> My *ieugen/page* page  looks like this and it works. Now let's see if I
>>> can manage to render the content using the thymeleaf rendering service
>>> or another way.
>>>
>>> Note to who is reading: Is there a simpler/better way to solve this?
>>>
>>> <html data-th-with="valueMap=${resource.getValueMap()}">
>>> <head>
>>> </head>
>>> <body>
>>> <div class="container">
>>>   <div class="panel panel-primary">
>>>     <span data-th-text="${valueMap.get('jcr:title')}">SIMPLE PAGE</span>
>>>   </div>
>>> </div>
>>> </body>
>>> </html>
>> There is a sample for Thymeleaf with Sling Models:
>>
>> https://github.com/apache/sling-samples/tree/master/fling
>>
>> Are you aware of it? Tip: Use Sling Models.
>>
>> Regards,
>> O.
>>
>>> On 28.05.2018 03:35, Ioan Eugen Stan wrote:
>>>> Hello,
>>>>
>>>> (Dear lazy sling community)
>>>>
>>>> I'm working to implement my first sling application / pages. We have to
>>>> deploy a *Terms of use* page that need to be translated across multiple
>>>> languages.
>>>>
>>>> I figured this should be easy with Sling - and it's not quite as I
>>>> expected :( .
>>>>
>>>> The solution that I have settled for in my head is using thymeleaf
>>>> templates and sling i18n with json files. However I need some help
>>>> implementing it.
>>>>
>>>> I'm sharing what is in my head, please help correct if I am wrong. I
>>>> have been at this (and other sling related stuff - content loading,
>> etc)
>>>> for the past few days.
>>>>
>>>> My page is going to live in */content**/terms-of-us**e.ht**ml*. It's a
>>>> *nt:file*, *sling:res**ource* with *sling:resourceType =
>> **ieugen**/page*
>>>> .
>>>>
>>>> Now, let's put translations for the page under
>>>>
>> */lib/trans**lations/content/t**erms**-of-use**.htlm/{english**.**json*,
>>>> *deuts**ch.json}* . These files should follow the format described in
>> [1].
>>>> My goal is for the content of the "/content/terms-of-use.html" node to
>>>> be a thymeleaf template itself. This template will use attributes like
>>>> th-text="#{text-id-from-translation-file}".
>>>>
>>>> Now, the script "*ieu**gen/page*" should to the following:
>>>>
>>>> - take the content of the JCR node
>>>>
>>>> - load the proper translation file based on the requested language and
>>>> the node currently being rendered.
>>>>
>>>> - render the content of the node (thymeleaf template - or any other
>>>> template language - handlebars?? ) by providing a context with the
>>>> translation files loaded
>>>>
>>>> - extra: the content might be rendered inside a layout defined by
>>>> ieugen/page script - with common headers and footers.
>>>>
>>>> My goal is to be able to create pages that are easy to
>> internationalize.
>>>> So far I have a few setbacks:
>>>>
>>>> 1. I don't know how to render resource properties.
>>>>
>>>> 2. I don't know how to render a template inside a script.
>>>>
>>>> So far, my script looks like this:
>>>>
>>>> <!DOCTYPE html>
>>>> <html
>>>>
>> data-th-with="*valueMap=${resource.adaptTo(@org.apache.sling.api.resource.
>>>> ValueMap@class)}*"> <head>
>>>>   <!-- Common head -->
>>>> </head>
>>>> <body>
>>>> <div class="container">
>>>>   <span data-th-text="${resource}">This works prints the resource
>> </span>
>>>>   <span data-th-text="${valueMap.attribute['jcr:title']}">*This fails -
>>>> valueMap is null* </span>
>>>>   <div>
>>>>      <p>*How do I render node content here**?**Node content is a
>>>> thymeleaf? template* </p>
>>>>   </div>
>>>> </div>
>>>> <footer>Common footer</footer>
>>>> </body>
>>>> </html>
>>>>
>>>> Thanks,
>>>>
>>>> [1]
>>>>
>> https://sling.apache.org/documentation/bundles/internationalization-suppor
>>>> t-i18n.html#json-file-based
>>


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to