Skip to content

Flattening language files, adding eslint rule to catch broken text key references #3323

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

Merged
merged 9 commits into from
Apr 29, 2025

Conversation

olemartinorg
Copy link
Contributor

Description

I noticed that the text key used in the helpText for 'bolignummer' in the Address component was broken:

20250426_13h51m11s_grim

Typescript can't help us much here, because the expected type is either just any string (for text resources defined in an app) or a valid text key as defined in en.ts/nb.ts/nn.ts. However, literal strings given as a language key should always point to text keys that are defined in app-frontend, so eslint can do that (and differentiate between a variable containing a string and a literal string) to warn us when making this mistake.

Also flattening our text files is something I've been thinking about for a long time (it may look nicer with nested objects, but it's just indirection and a format you 'need to know about'). By flattening them, we get back proper autocomplete support via the typescript types, along with simpler code to look them up.

Related Issue(s)

  • closes #{issue number}

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Sorry, something went wrong.

Ole Martin Handeland added 5 commits April 26, 2025 13:48
…gs given to the Lang component or lang()/langAsString() are valid language keys.
…on tool for legacy usage in CustomWebComponent.tsx
@olemartinorg olemartinorg added kind/bug Something isn't working backport-ignore This PR is a new feature and should not be cherry-picked onto release branches labels Apr 26, 2025
@olemartinorg olemartinorg self-assigned this Apr 26, 2025
@olemartinorg olemartinorg moved this to 🔎 Review in Team Apps Apr 26, 2025
Ole Martin Handeland added 2 commits April 26, 2025 14:41
Copy link
Member

@bjosttveit bjosttveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, I keep forgetting to add general. when using language and getting frustrated 😅

Ole Martin Handeland added 2 commits April 29, 2025 20:20
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
41.4% Coverage on New Code (required ≥ 45%)

See analysis details on SonarQube Cloud

@olemartinorg olemartinorg merged commit 1550668 into main Apr 29, 2025
14 of 15 checks passed
@olemartinorg olemartinorg deleted the bug/wrong-text-keys branch April 29, 2025 18:51
@github-project-automation github-project-automation bot moved this from 🔎 Review to 🧪 Test in Team Apps Apr 29, 2025
@olemartinorg olemartinorg moved this from 🧪 Test to ✅ Done in Team Apps May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-ignore This PR is a new feature and should not be cherry-picked onto release branches kind/bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants