Skip to content

Auto-clear persisted workbench state when Eclipse is launched with a different locale#4166

Merged
merks merged 1 commit into
eclipse-platform:masterfrom
deepika-u:locale_change
Jul 7, 2026
Merged

Auto-clear persisted workbench state when Eclipse is launched with a different locale#4166
merks merged 1 commit into
eclipse-platform:masterfrom
deepika-u:locale_change

Conversation

@deepika-u

@deepika-u deepika-u commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The Problem
When Eclipse is launched with -nl and the workspace already has a persisted workbench.xmi from a previous session in a different language, the UI starts up showing stale labels - view tabs like Declaration, Problems and Javadoc remain in the old language until the user manually clicks on each tab. The only workaround today is launching with -clearPersistedState, which throws away the entire workbench layout every time.

Fixes #3108

Root Cause
Eclipse caches view labels and other UI strings directly in workbench.xmi at shutdown. On the next launch, these cached values are rendered before the NL bundles have a chance to supply the correct translated strings. Since nothing was comparing the current locale against the one used in the previous session, stale labels went undetected.

Fix in-detail
A single new private method - hasNlChanged() - is introduced in E4Application. On each startup it does three things:

  • Reads the locale recorded from the last launch from a small properties file (last_nl.properties) stored alongside workbench.xmi
  • Compares it against the current Platform.getNL()
  • If they differ, signals the existing CLEAR_PERSISTED_STATE mechanism to rebuild the workbench model fresh from the correct NL bundles

If the locale is unchanged, or if this is the first ever launch, nothing happens - the user's layout is fully preserved.

What Changes

  • E4Application.java - the only file modified
  • last_nl.properties - a new small file written to <workspace>/.metadata/.plugins/org.eclipse.e4.workbench/ at first launch, updated on each locale change

No new dependencies. No schema changes. No impact on the common single-locale case(except that locale is being saved now).

Notes

  • The CLEAR_PERSISTED_STATE path used here is well-tested and already used in production via the -clearPersistedState launch argument. This change simply triggers it conditionally and automatically.
  • Locale changes between Eclipse sessions are infrequent - the cost of a one-time layout reset in that scenario is acceptable and consistent with user expectations.
  • First launch on a fresh workspace is handled gracefully - last_nl.properties is created silently with no side effects.
  • Path resolution uses instanceLocation.getURL().toURI() rather than getFile() to correctly handle Windows paths, where getFile() returns a URL-style path with a leading /C:/ that Path.of() rejects on Windows.

Without Fix

  1. Locale is English ->
image
  1. Locale changed to French, immediately seen labels ->
image
  1. On refresh of the tabs, it then shows ->
image

With Fix

  1. Locale is English ->
image
  1. Locale changed to French, immediately seen labels ->
image

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Test Results

   855 files  ±0     855 suites  ±0   54m 31s ⏱️ - 10m 5s
 8 104 tests ±0   7 861 ✅ +1  243 💤 ±0  0 ❌  - 1 
20 214 runs  ±0  19 560 ✅ +1  654 💤 ±0  0 ❌  - 1 

Results for commit 74ed1a9. ± Comparison against base commit 8cae023.

♻️ This comment has been updated with latest results.

@deepika-u

Copy link
Copy Markdown
Contributor Author

@merks : When you get some time, can you review this please?

@merks merks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the whole thing could be cleaner and more "modern" if you use Path/Files instead of File.

}
} catch (IOException e) {
// Cannot read - safe to skip, don't trigger clear
return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this occurs for whatever reason that the file will never be written.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Replaced return false with localeChanged = true so that execution falls through to the write block regardless - meaning a corrupt or unreadable file gets repaired or recreated on the same launch rather than staying broken indefinitely.

boolean localeChanged = false;

// Read previously saved locale if file exists
if (nlFile.exists()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a nit, but if it's a directory it also exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Changed nlFile.exists() to Files.isRegularFile() which returns true only for actual regular files, correctly excluding directories and anything else that isn't a plain file.

return false;
}

File stateDir = new File(instanceLocation.getURL().getFile(), ".metadata" + File.separator //$NON-NLS-1$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you used Path you could use resolve and wouldn't need to do all the file separator logic...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Replaced File with Path.of(instanceLocation.getURL().toURI()) and chained .resolve() calls for each path segment - no more manual File.separator concatenation.

@deepika-u

Copy link
Copy Markdown
Contributor Author

@merks : Updated the fix now, can you take a look once you get some time please.

@merks merks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that looks nice! Thank you!!

@deepika-u

Copy link
Copy Markdown
Contributor Author

Yes, that looks nice! Thank you!!

Thanks alot for the quick review :)

@merks merks merged commit de52966 into eclipse-platform:master Jul 7, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some ViewParts are not localized at startup when using -nl <language> parameter

2 participants