Skip to content

Compile-time issues with React tutorial #537

Open
@sandalwoodbox

Description

@sandalwoodbox

In https://github.com/projectfluent/fluent.js/wiki/React-Tutorial, I had to make the following adjustments to the final generateBundles function to get it to compile:

Current:

// Generate bundles for each locale.
async function generateBundles() {
    return languages.map(locale => {
        const translations = await getMessages(locale);
        const bundle = new FluentBundle(locale);
        bundle.addMessages(translations);
        return bundle;
    });
}

Fixed:

// Generate bundles for each locale.
async function generateBundles() {
  return languages.map(async (locale) => {
    const translations = await getMessages(locale);
    const bundle = new FluentBundle(locale);
    bundle.addResource(new FluentResource(translations));
    return bundle;
  });
}

At first I was getting Unexpected reserved word 'await' for getMessages; I fixed that by marking the map call as async. I then had to update addMessages to addResource because addMessages doesn't exist.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions