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

when a custom websocket provider is used, not all strings are getting localized #13237

Closed
hyddel opened this issue Jan 3, 2024 · 7 comments
Closed

Comments

@hyddel
Copy link

hyddel commented Jan 3, 2024

Bug Description:

when a custom websocket provider is used, not all strings are getting localized

Steps to Reproduce:

  1. Use the attached sample code
  2. Run the following command: yarn
  3. Include this change: https://github.com/eclipse-theia/theia/pull/13199/files (I have directly edited the lib file in the node_modules present in the root)
  4. Run the following command: yarn prepare && cd browser-app && yarn download:plugins && yarn local_start
  5. Go to http://localhost:4444/
  6. wait for code editor to load and then change locale to es
  7. Observe that the strings under "File" and "Edit" are not translated.

Additional Information

  • Operating System: Mac
  • Theia Version: 1.43.0

custom-code-editor.zip

@hyddel
Copy link
Author

hyddel commented Jan 4, 2024

@msujew any thoughts ?

@msujew
Copy link
Member

msujew commented Jan 5, 2024

@hyddel Do you have the same issue in 1.45 with the new ServiceConnectionProvider architecture? It seems to work for me pretty well:

image

Preload module for ServiceConnectionProvider override
import { ConnectionSource } from './messaging/connection-source';
import { LocalConnectionProvider, RemoteConnectionProvider, ServiceConnectionProvider } from './messaging/service-connection-provider';
import { ContainerModule, injectable } from 'inversify';
import { WebSocketConnectionSource } from './messaging/ws-connection-source';

@injectable()
export class CustomWebSocketConnectionProvider extends ServiceConnectionProvider {

    constructor() {
        super();
        console.log('=====================loading custom connection provider===============');
    }

}

export default new ContainerModule((bind, _, __, rebind) => {
    const backendServiceProvider = Symbol('backendServiceProvider');
    bind(CustomWebSocketConnectionProvider).toSelf().inSingletonScope();
    bind(backendServiceProvider).toDynamicValue(ctx => {
        bind(ServiceConnectionProvider).toSelf().inSingletonScope();
        const container = ctx.container.createChild();
        container.bind(ConnectionSource).toService(WebSocketConnectionSource);
        return container.get(CustomWebSocketConnectionProvider);
    }).inSingletonScope();
    rebind(LocalConnectionProvider).toService(backendServiceProvider);
    rebind(RemoteConnectionProvider).toService(backendServiceProvider);
});

@hyddel
Copy link
Author

hyddel commented Jan 5, 2024

@msujew we are actually using 1.42.1 where we are seeing this issue. We have tried 1.43.0 to see if the issue is fixed but facing the same issue. I think we cannot upgrade to 1.45.0 because we might have to adjust our customizations and also the timeline does not permit us to migrate to 1.45.0.

Any thoughts on why it is not working in 1.43.0 or 1.42.1 ?

@msujew
Copy link
Member

msujew commented Jan 6, 2024

@hyddel in your code, you're importing by doing this:

import { WebSocketConnectionProvider } from "@theia/core/lib/browser";

However, importing from @theia/core/lib/browser loads files that expect localizations are already available during load time. You need to adjust the import:

import { WebSocketConnectionProvider } from "@theia/core/lib/browser/messaging/ws-connection-provider";

That way you don't accidentally load files that aren't allowed to be loaded yet. The preload is a very special phase in the frontend application lifecycle and requires special care to work correctly.

@hyddel
Copy link
Author

hyddel commented Jan 6, 2024

I have tried that but still facing the same issue.

@msujew
Copy link
Member

msujew commented Jan 6, 2024

@hyddel It works for me. I've just replaced both imports of the WebSocketConnectionProvider and it works as expected:

image
image

Please ensure that you have no general @theia/core/lib/browser import in any of your preload code, even just transitively. It will automatically load code that expects that the localizations are already loaded.

If you want to figure out which code calls the localization code too early, you can set a breakpoint in the nls.localizeByDefault function and follow the call chain.

@hyddel
Copy link
Author

hyddel commented Jan 7, 2024

it is working for me too. I have missed to replace the import at one place.
thank you so much.

@hyddel hyddel closed this as completed Jan 7, 2024
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

No branches or pull requests

2 participants