2

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.

ean
  • 41
  • 1
  • 4

2 Answers2

2

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.

sholsinger
  • 3,028
  • 2
  • 23
  • 40
0

you can get the current locale with request.locale

var currentLocale = request.locale;
m4t.z
  • 87
  • 3