Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Localization] : Language Variables in HTML Page are not respecting the Language set in current Session #29946

Open
jcastro-dotcms opened this issue Sep 10, 2024 · 2 comments

Comments

@jcastro-dotcms
Copy link
Contributor

jcastro-dotcms commented Sep 10, 2024

Parent Issue

Reported via Enterprise Support. No ticket number available yet.

Problem Statement

According to our Multi-Site Language Configuration documentation, dotCMS Users/Developers are able to access the current Session via the $request object, and update the Language that HTML Pages are being rendered in.

However, it seems that such an update is not working as expected when it comes to the $text ViewTool returning Language Variables in the updated Language. If your default language is English, it'll keep returning the value of the Language Variable in English.

Steps to Reproduce

  1. Log into dotCMS, go to the Site > Templates portlet.
  2. Create an Advanced Template, and name it My Custom Template. Add the following source code:
<html>
    <header>
        <title>My Custom Template</title>
    </header>
    <body>
        <div>
            #if($UtilMethods.isSet($!{request.getParameter("lang")}))
                #set($languages = $text.getLanguages())
                #foreach($language in $languages)
                    ## ========================================================================
                    ## Use the first language that matches if no country code is specified.
                    ## ========================================================================
                    #if($UtilMethods.contains($!{language.getLanguageCode()}, $!{request.getParameter("lang")}))
                        #set($languageId = $!{language.id})
                        #set($flag = "")
                        ## ========================================================================
                        ## Update our session language
                        ## ========================================================================
                        #if(!$UtilMethods.contains($flag, "true"))
                            $request.getSession().setAttribute("com.dotmarketing.htmlpage.language", "$languageId")
                            $request.getSession().setAttribute("flag", "true")
                        #end
                    #end
                #end
            #else
                <h4>No language was specified, using the default one</h4>
            #end
            <p>Current language ID: $request.getSession().getAttribute("com.dotmarketing.htmlpage.language")</p> 
            <p>Language Variable 'customvar': $text.get("customvar")</p>
        </div>
    </body>
</html>
  1. Go to the Content > Search portlet, and create a Language Variable in both English and Spanish:
    3.1. Language = English, Key = customvar, Value = My website
    3.2. Language = Spanish, Key = customvar, Value = Mi sitio web
  2. Create an HTML Page using the My Custom Template you created before named test-page. Create it in both English and Spanish.
  3. Open it in the back-end. You'll see that the Language Variable shows up in both languages depending on the selected page language. This is the expected behavior.
  4. Now, open another browser or an Incognito Window with this URL: http://localhost:8080/test-page?lang=es . You'll see that the Language Variable is displayed in English:
Screenshot 2024-09-10 at 10 45 32 AM

Acceptance Criteria

Updating the currently selected Language in the Session object must render Language Variables in the specified Language.

dotCMS Version

Version 24.08.20 and older, and latest master.

Proposed Objective

Core Features

Proposed Priority

Priority 2 - Important

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

https://dotcms.slack.com/archives/C028Z3R2D/p1725628920476489

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

@wezell
Copy link
Contributor

wezell commented Sep 12, 2024

This is not the way to set languages in dotCMS. Use either a rule or a vanityurl. Doing languages this way will break page cache.

@wezell wezell closed this as completed Sep 12, 2024
@wezell wezell reopened this Sep 12, 2024
@wezell
Copy link
Contributor

wezell commented Sep 12, 2024

We need to fix this in the doc site @jdcmsd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Next 1-3 Sprints
Development

No branches or pull requests

3 participants