Skip to content

Incomplete English translation #153538

Closed

Description

Testing #153391 in Firefox with de-ch (Swiss German) set.

  • Open command palette and search for Remote Repositories commands
  • 🐛 The first command has a partly English, partly de-ch line under it (Focus on and View in English, Remoterepositorys seems to be de-ch translated)
    image

Activity

  1. TylerLeonhardt commented on Jun 28, 2022

    @TylerLeonhardt
    Member

    Hmm yeah it should look like this (Desktop screenshot) with the English strings next to the German strings. I think this is a bug in how I'm applying the translations...
    image

  2. added
    bug
    l10n-platform
    on Jun 28, 2022
  3. added this to the July 2022 milestone on Jun 28, 2022
  4. TylerLeonhardt commented on Jul 1, 2022

    @TylerLeonhardt
    Member

    Just found out about these functions on the desktop side:

    private async translateManifest(extensionLocation: URI, extensionManifest: IExtensionManifest, nlsConfiguration: NlsConfiguration): Promise<IExtensionManifest> {
    const localizedMessages = await this.getLocalizedMessages(extensionLocation, extensionManifest, nlsConfiguration);
    if (localizedMessages) {
    try {
    const errors: ParseError[] = [];
    // resolveOriginalMessageBundle returns null if localizedMessages.default === undefined;
    const defaults = await this.resolveOriginalMessageBundle(localizedMessages.default, errors);
    if (errors.length > 0) {
    errors.forEach((error) => {
    this.logService.error(this.formatMessage(extensionLocation, localize('jsonsParseReportErrors', "Failed to parse {0}: {1}.", localizedMessages.default?.path, getParseErrorMessage(error.error))));
    });
    return extensionManifest;
    } else if (getNodeType(localizedMessages) !== 'object') {
    this.logService.error(this.formatMessage(extensionLocation, localize('jsonInvalidFormat', "Invalid format {0}: JSON object expected.", localizedMessages.default?.path)));
    return extensionManifest;
    }
    const localized = localizedMessages.values || Object.create(null);
    this.replaceNLStrings(nlsConfiguration.pseudo, extensionManifest, localized, defaults, extensionLocation);
    } catch (error) {
    /*Ignore Error*/
    }
    }
    return extensionManifest;
    }
    private async getLocalizedMessages(extensionLocation: URI, extensionManifest: IExtensionManifest, nlsConfiguration: NlsConfiguration): Promise<LocalizedMessages | undefined> {
    const defaultPackageNLS = joinPath(extensionLocation, 'package.nls.json');
    const reportErrors = (localized: URI | null, errors: ParseError[]): void => {
    errors.forEach((error) => {
    this.logService.error(this.formatMessage(extensionLocation, localize('jsonsParseReportErrors', "Failed to parse {0}: {1}.", localized?.path, getParseErrorMessage(error.error))));
    });
    };
    const reportInvalidFormat = (localized: URI | null): void => {
    this.logService.error(this.formatMessage(extensionLocation, localize('jsonInvalidFormat', "Invalid format {0}: JSON object expected.", localized?.path)));
    };
    const translationId = `${extensionManifest.publisher}.${extensionManifest.name}`;
    const translationPath = nlsConfiguration.translations[translationId];
    if (translationPath) {
    try {
    const translationResource = URI.file(translationPath);
    const content = (await this.fileService.readFile(translationResource)).value.toString();
    const errors: ParseError[] = [];
    const translationBundle: TranslationBundle = parse(content, errors);
    if (errors.length > 0) {
    reportErrors(translationResource, errors);
    return { values: undefined, default: defaultPackageNLS };
    } else if (getNodeType(translationBundle) !== 'object') {
    reportInvalidFormat(translationResource);
    return { values: undefined, default: defaultPackageNLS };
    } else {
    const values = translationBundle.contents ? translationBundle.contents.package : undefined;
    return { values: values, default: defaultPackageNLS };
    }
    } catch (error) {
    return { values: undefined, default: defaultPackageNLS };
    }
    } else {
    const exists = await this.fileService.exists(defaultPackageNLS);
    if (!exists) {
    return undefined;
    }
    let messageBundle;
    try {
    messageBundle = await this.findMessageBundles(extensionLocation, nlsConfiguration);
    } catch (error) {
    return undefined;
    }
    if (!messageBundle.localized) {
    return { values: undefined, default: messageBundle.original };
    }
    try {
    const messageBundleContent = (await this.fileService.readFile(messageBundle.localized)).value.toString();
    const errors: ParseError[] = [];
    const messages: MessageBag = parse(messageBundleContent, errors);
    if (errors.length > 0) {
    reportErrors(messageBundle.localized, errors);
    return { values: undefined, default: messageBundle.original };
    } else if (getNodeType(messages) !== 'object') {
    reportInvalidFormat(messageBundle.localized);
    return { values: undefined, default: messageBundle.original };
    }
    return { values: messages, default: messageBundle.original };
    } catch (error) {
    return { values: undefined, default: messageBundle.original };
    }
    }
    }
    /**
    * Parses original message bundle, returns null if the original message bundle is null.
    */
    private async resolveOriginalMessageBundle(originalMessageBundle: URI | null, errors: ParseError[]): Promise<{ [key: string]: string } | null> {
    if (originalMessageBundle) {
    try {
    const originalBundleContent = (await this.fileService.readFile(originalMessageBundle)).value.toString();
    return parse(originalBundleContent, errors);
    } catch (error) {
    /* Ignore Error */
    return null;
    }
    } else {
    return null;
    }
    }
    /**
    * Finds localized message bundle and the original (unlocalized) one.
    * If the localized file is not present, returns null for the original and marks original as localized.
    */
    private findMessageBundles(extensionLocation: URI, nlsConfiguration: NlsConfiguration): Promise<{ localized: URI; original: URI | null }> {
    return new Promise<{ localized: URI; original: URI | null }>((c, e) => {
    const loop = (locale: string): void => {
    const toCheck = joinPath(extensionLocation, `package.nls.${locale}.json`);
    this.fileService.exists(toCheck).then(exists => {
    if (exists) {
    c({ localized: toCheck, original: joinPath(extensionLocation, 'package.nls.json') });
    }
    const index = locale.lastIndexOf('-');
    if (index === -1) {
    c({ localized: joinPath(extensionLocation, 'package.nls.json'), original: null });
    } else {
    locale = locale.substring(0, index);
    loop(locale);
    }
    });
    };
    if (nlsConfiguration.devMode || nlsConfiguration.pseudo || !nlsConfiguration.language) {
    return c({ localized: joinPath(extensionLocation, 'package.nls.json'), original: null });
    }
    loop(nlsConfiguration.language);
    });
    }
    /**
    * This routine makes the following assumptions:
    * The root element is an object literal
    */
    private replaceNLStrings<T extends object>(pseudo: boolean, literal: T, messages: MessageBag, originalMessages: MessageBag | null, extensionLocation: URI): void {
    const processEntry = (obj: any, key: string | number, command?: boolean) => {
    const value = obj[key];
    if (isString(value)) {
    const str = <string>value;
    const length = str.length;
    if (length > 1 && str[0] === '%' && str[length - 1] === '%') {
    const messageKey = str.substr(1, length - 2);
    let translated = messages[messageKey];
    // If the messages come from a language pack they might miss some keys
    // Fill them from the original messages.
    if (translated === undefined && originalMessages) {
    translated = originalMessages[messageKey];
    }
    let message: string | undefined = typeof translated === 'string' ? translated : (typeof translated?.message === 'string' ? translated.message : undefined);
    if (message !== undefined) {
    if (pseudo) {
    // FF3B and FF3D is the Unicode zenkaku representation for [ and ]
    message = '\uFF3B' + message.replace(/[aouei]/g, '$&$&') + '\uFF3D';
    }
    obj[key] = command && (key === 'title' || key === 'category') && originalMessages ? { value: message, original: originalMessages[messageKey] } : message;
    } else {
    this.logService.warn(this.formatMessage(extensionLocation, localize('missingNLSKey', "Couldn't find message for key {0}.", messageKey)));
    }
    }
    } else if (isObject(value)) {
    for (const k in value) {
    if (value.hasOwnProperty(k)) {
    k === 'commands' ? processEntry(value, k, true) : processEntry(value, k, command);
    }
    }
    } else if (isArray(value)) {
    for (let i = 0; i < value.length; i++) {
    processEntry(value, i, command);
    }
    }
    };
    for (const key in literal) {
    if (literal.hasOwnProperty(key)) {
    processEntry(literal, key);
    }
    }
    }

    Which seems to go through the manifest and turn some strings into ILocalizedStrings. I followed up with Sandeep Somavarapu (@sandy081) to understand how this works.

  5. sandy081 commented on Jul 4, 2022

    @sandy081
    Member

    This code was originally written by Alexandru Dima (@alexdima) so I would ask him to know how this works.

  6. alexdima commented on Jul 13, 2022

    @alexdima
    Member

    This code was originally written by Alexandru Dima (@alexdima)

    Not quite, it was originally written by Dirk Bäumer (@dbaeumer) , but I'm happy to try and help. My understanding is that the code is taking a JSON object that looks like this:

    { "some": { "deep": { "property": "%some.key%", "bar": ["%some.key2%"] } } }
    

    Together with another JSON object that looks like this:

    { "some.key": "My string value", "some.key2": "My second string value" }
    

    And produces a JSON object that looks like this by substituting all string values of the shape "%...%" with their corresponding value:

    { "some": { "deep": { "property": "My string value", "bar": ["My second string value"] } } }
    
  7. added
    unreleased
    insiders-released
    and removed
    unreleased
    on Aug 23, 2022
  8. added
    verified
    verification-found
    and removed
    verified
    on Aug 25, 2022
  9. andreamah commented on Aug 25, 2022

    @andreamah
    Contributor

    I still see this on firefox:

    image

    The first option's english translation still looks wrong? (tested on https://insiders.vscode.dev/)

  10. removed
    insiders-released
    on Aug 25, 2022
  11. TylerLeonhardt commented on Aug 25, 2022

    @TylerLeonhardt
    Member

    The first one is still wrong because of #157015 so we'll track that there.

    However, the rest now have the English string underneath which they use to not have, which means this is fixed and verified 😃

  12. added
    verified
    and removed
    verification-found
    on Aug 25, 2022
  13. locked and limited conversation to collaborators on Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugl10n-platformverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions