Is there a server side function in SFCC to get Locale? Thank you!!!
I am localizing a sfcc site, and need to update the en_gb locale in thousands of hard coded strings (in a xml file obtained from Merchant Tools > Content > Import & Export) to server side code that will dynamically insert the correct locale, i.e. en_gb, fr_fr, etc. I know there are a few server side functions like $URL()$ that can run before content is rendered. Is there one to get the Locale?
here is what I have now... https://www.example.com/en_gb/holiday-sale-event/?prefn1=productType&prefv1=Shoes
ideally, I'm looking for something like: https://www.example.com/$Locale()$/holiday-sale-event/?prefn1=productType&prefv1=Shoes
Expected results would be:
https://www.example.com/en_gb/holiday-sale-event/?prefn1=productType&prefv1=Shoes
https://www.example.com/en_nl/holiday-sale-event/?prefn1=productType&prefv1=Shoes
https://www.example.com/fr_fr/holiday-sale-event/?prefn1=productType&prefv1=Shoes
https://www.example.com/de_de/holiday-sale-event/?prefn1=productType&prefv1=Shoes
...etc., depending on locale.
You should be using $url()$ to generate the URL which will automatically populate the correct locale string in the URL.
Assuming that the above examples are links for a refined category search within a category with the ID: holiday-sales-event Then your first example would be represented as such:
$url(Search-Show,cgid,holiday-sales-event,prefn1,productType,prefv1,shoes)$
This would produce the correct localized URL for whatever locale context the content is being rendered for.
Since the “holiday-sales-event” portion of the URL is likely to be localized itself, then your intended approach would result in either 404s or redirects at the very least.
you can get the current locale with request.locale
var currentLocale = request.locale;
Related
I'm using the Elouqa Rest API in an integration with another product and I want to implement a file browser. As part of this I want to get a list of the folders inside another folder. Theapi documents here say that a search string can be appended but don't give any clues as to the format of the search string. I've tried various things but so far I'm just getting empty results. An example is here:
/API/rest/1.0/assets/email/folders?search=folderId+%3D+250
I've tried with and without +'s and with and without url encoding the = sign, also various combinations of quote marks but so far nothing.
I believe what you want is a slightly different endpoint e.g.:
/API/rest/1.0/assets/email/folder/250/contents
Which would provide a list of folders contained with folder 250
If you wanted to search for a given folder name then you would use
/API/rest/1.0/assets/email/folders?search=foldername
Hope that helps!
I have mount Page in this form (with one predefined parameter):
mountPage("/lista/${variant}", StronaEntityV2.class);
when parameter "variant" is given all is OK. But when parameter is absent (is OK too from application point of view) URL is build in form
wicket/bookmarkable/all....package...StronaEntityV2?8
It is ok too, but I will know that situation. In simple situation (with one predefined parameter) checking parameter is good, but in more complicated isn't so simple (and must maintain code in distinct places).
My ideal imaged solution is event
page.OnPageIsMountedOn(URL to_me)
I will accept wide range of solutions.
FORMAL: please integrate synonyms on tags wicket-1.6 & wicket-6, and create new wicket-7
Your page is configured to listen to /lista/${variant}.
When you do: setResponsePage(StronaEntityV2.class, paramsWithVariant) then Wicket will use the mount point and produce: /lista/variantValue.
But if you do: setResponsePage(StronaEntityV2.class), i.e. no PageParameters provided, then Wicket will ignore /lista/${variant} (because it doesn't match) and will produce a "default" page url, i.e. /wicket/bookmarkable/com.example.StronaEntityV2.
So the application controls which url should be used.
You can use optional parameter placeholder: /lista/#{variant}. Note that I use # instead of $ now. This way Wicket will produce /lista/ when there is no variant parameter provided. In the page constructor you will know that the url is always "/lista" but the parameter may be null, so better use: pageParameters.get("variant").toXyz(defaultValue) or .toOptionalXyz().
If I run my play framework application with "play run" the localisation is fine. But if I do a "play dist" then use the start command, then the original English messages appear.
I have found, that if I change the classpath order in the start script putting the jar containing my messages file to the first place, then the localisation is fine.
Is there any better way to do this?
It is the same, if I copy the conf/messages to conf/messages.hu and set application.langs="hu" in the application.conf.
And stays the same, if I change my browser settings, so this is in the request header: "Accept-Language:hu,en-US;q=0.8,en;q=0.6". Still English messages (only, if they are the built in keys. My custom keys are translated correctly).
We have figured it out.
There is a custom field constructor used. My assumption was, that it is using the implicit lang parameter, but this is not the case. The lang must be given to the elements.errors() as parameter, and the current lang setting is stored in the elements.lang attribute. This is stated in the documentation, but we missed it. So the implicit lang parameter should not be used in the field template, because it contains wrong value.
The solution was this: #elements.errors(elements.lang)
#elements.input
<span class="errors">#elements.errors(elements.lang).mkString(", ")</span>
I've made a very simple sinatra application which displays a frameset with 3 frames. When I set the 'src' parameter for the the frames however, sinatra re-encodes the query string I chose.
For example I enter:
"url.com/page?var1=val1&var2=val2"
What I end up seeing however is something like:
"url.com/page?var1=val1&var2=val2"
All my &'s were turned into &-a-m-p-;'s. Is there anyway to disable this? Why does this happen?
Thanks,
This is probably happening because you have an "escape all html" flag turned on somewhere. Your template language should support flagging strings as "safe"--check out http://www.sinatrarb.com/faq.html#auto_escape_html for more details.
I'm using toLocalizedTime to output a date, as below
<span tal:content="python:here.toLocalisedTime(date.get('start_date'))"/>
This outputs eg. 2007/08/02, I'm just curious as to how one would alter the output so that it reads 02/08/2007
I'm not having much luck finding much info on toLocalizedTime, would someone point me in the right direction?
This depends on whether you have English selected as the site language (Site Setup >> Language). If so, then the default settings are used. You can change the defaults by dropping down into the ZMI, then into 'portal_properties', then 'site_properties'. The fields to change are either 'localTimeFormat' or 'localLongTimeFormat' depending on whether you pass in 'long_format=1' to the toLocalisedTime function.
If on the other hand, you have translations set up, the format may instead be pulled from the translation file for the locale selected. I'm not sure what is the easy way to change the format in this case (other than switching the site back to English). I guess you can register your own translation file but I've never needed to do that so you're going to have to look up the details.
Date string formatting follows the Python rules (http://docs.python.org/library/time.html#time.strftime).
Perhaps even more detail than you need:
here.toLocalizedTime()
is defined in the plone browser view at...
CMFPlone/browser/ploneview.py
which looks up the 'translation_service' utility, to call its 'ulocalized_time' function, defined at...
CMFPlone/TranslationServiceTool.py
which itself calls the 'ulocalized_time' function defined at...
CMFPlone/i18nl10n.py
As always, you can learn interesting things by grepping the source code ;-)
For an up to date answer for Plone 4.3 (after going through the source code)
These fields are now in the registry found at:
http://localhost:8080/yoursite/portal_registry
Then filter on "i18nl10n", which should give you the 4 fields you need to change.