codeant-ai-for-open-source[bot] commented on code in PR #34629:
URL: https://github.com/apache/superset/pull/34629#discussion_r3479708701


##########
superset-frontend/src/utils/localeUtils.ts:
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { rtlLanguages } from 'src/constants';
+import getBootstrapData from './getBootstrapData';
+
+export type TextDirection = 'ltr' | 'rtl';
+
+export function getLanguageCodeFromLocale(locale: string): string {
+  return locale.split('-')[0];

Review Comment:
   **Suggestion:** Locale parsing only strips `-` but backend bootstrap locales 
can be underscore-formatted (`ar_SA`, `fa_IR`) and region-preserving values are 
intentionally emitted. In those cases this returns the full locale token 
instead of the base language, so RTL languages with region suffixes are 
misclassified as LTR and direction initialization is wrong. Normalize by 
handling both `-` and `_` separators (and lowercasing) before checking against 
the RTL language list. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ RTL users with region locales get incorrect LTR layout.
   - ⚠️ Header language picker misaligns theme direction for RTL.
   - ⚠️ Bootstrap locale normalization not respected by direction utility.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Configure Superset with a region-specific RTL language code (for example 
`"ar_SA"`) in
   `LANGUAGES` inside `superset_config.py`, so that backend locale 
normalization in
   `superset/views/base.py:487-498` preserves `"ar_SA"` as `language` when the 
browser sends
   `locale='ar-SA'` and `"ar_SA"` is present in `LANGUAGES`.
   
   2. Load the main Superset UI so bootstrap data is generated;
   `superset/views/base.py:534-549` builds `bootstrap_data` and sets `"locale": 
language`
   (here `"ar_SA"`), while `menu_data()` at `superset/views/base.py:25-69` 
exposes the
   current session locale as `navbar_right["locale"] = session.get("locale", 
"en")` at line
   316 (which will be `"ar_SA"` after picking that language in the header).
   
   3. On the frontend, `getBootstrapData()` (imported in
   `superset-frontend/src/utils/localeUtils.ts:20`) returns this JSON; 
`getBootstrapLocale()`
   at `localeUtils.ts:33-35` reads `common.menu_data.navbar_right.locale || 
common.locale`,
   so with the above configuration it returns `"ar_SA"` to the client.
   
   4. During theme initialization, `initializeDirectionFromLocale()` in
   `superset-frontend/src/theme/ThemeController.ts:724-728` calls
   `getDirectionFromLocale(getBootstrapLocale())`; `getDirectionFromLocale()` in
   `localeUtils.ts:28-30` invokes `getLanguageCodeFromLocale()` at 
`localeUtils.ts:24-25`,
   which currently does `locale.split('-')[0]`, so for `locale='ar_SA'` it 
returns `"ar_SA"`
   instead of `"ar"`, and since `rtlLanguages` in 
`superset-frontend/src/constants.ts:46-57`
   contains only base codes (e.g. `"ar"`, `"fa"`), 
`rtlLanguages.includes('ar_SA')` is false,
   causing `globalTheme.setDirection('ltr')` and rendering an incorrect LTR 
layout for RTL
   users on region-specific locales.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=442dd8eb14f949a6a2cfc854a9f07430&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=442dd8eb14f949a6a2cfc854a9f07430&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/utils/localeUtils.ts
   **Line:** 25:25
   **Comment:**
        *Logic Error: Locale parsing only strips `-` but backend bootstrap 
locales can be underscore-formatted (`ar_SA`, `fa_IR`) and region-preserving 
values are intentionally emitted. In those cases this returns the full locale 
token instead of the base language, so RTL languages with region suffixes are 
misclassified as LTR and direction initialization is wrong. Normalize by 
handling both `-` and `_` separators (and lowercasing) before checking against 
the RTL language list.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34629&comment_hash=6c333b2c7e3c9a928e0d5ec8abce3e57a388d9980037ca34f5b1d35f2a3d3a0b&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F34629&comment_hash=6c333b2c7e3c9a928e0d5ec8abce3e57a388d9980037ca34f5b1d35f2a3d3a0b&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to