How to use the @fluent/bundle.FluentBundle function in @fluent/bundle

To help you get started, we’ve selected a few @fluent/bundle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / fluent__bundle / fluent__bundle-tests.ts View on Github external
import { FluentBundle, FluentDateTime, FluentError, FluentNumber, FluentResource, Scope } from '@fluent/bundle';
import * as compat from '@fluent/bundle/compat';

// FluentBundle examples:
const bundle = new FluentBundle(['en-US']);
const compatBundle = new compat.FluentBundle(['en-US']);

// FluentResource examples:
const resource = new FluentResource(`test=Some other message with args arg1={$arg1} and arg2={$arg2}`);
bundle.addResource(resource, { allowOverrides: true });
const msg = bundle.getMessage('test');
if (msg && msg.value) {
    const args = {
        $arg1: "#1",
        $arg2: "#2"
    };
    const errors: Error[] = [];
    const formatted: string = bundle.formatPattern(msg.value, args, errors);
    console.log(formatted);
}
github projectfluent / fluent-web / src / index.js View on Github external
async function createContext(locale, resourceIds) {
  const ctx = new FluentBundle([locale]);

  // First fetch all resources
  const resources = await Promise.all(
    resourceIds.map(id => fetchResource(locale, id)),
  );

  // Then apply them preserving order
  for (const resource of resources) {
    ctx.addResource(resource);
  }
  return ctx;
}
github spacemeowx2 / LiveHelper / src / langs / index.tsx View on Github external
} else if (a.value > b.value) {
      return 'GT'
    } else {
      return 'LT'
    }
  },
  STR ([n]: FluentValue[]) {
    return n.value.toString()
  },
  MAYBE_HAS ([n]: FluentValue>[]) {
    return maybeHas(n.value) ? 'has' : 'none'
  }
}

for (const locale of Object.keys(LangMap)) {
  const bundle = new FluentBundle(locale, {
    functions
  })
  bundle.addResource(new FluentResource(LangMap[locale]))
  BundleMap[locale] = bundle
}

const langs = [chrome.i18n.getUILanguage(), ...Langs]
const bundles = langs.map(i => BundleMap[i]).filter(Boolean)

export const LocalizationProvider: React.FC = ({ children }) => {
  return 
    <>{children}
  
}
github mozilla / send / app / locale.js View on Github external
function makeBundle(locale, ftl) {
  const bundle = new FluentBundle(locale, { useIsolating: false });
  bundle.addMessages(ftl);
  return bundle;
}
github mozilla / send / server / locale.js View on Github external
function makeBundle(locale) {
  const bundle = new FluentBundle(locale, { useIsolating: false });
  bundle.addMessages(
    fs.readFileSync(path.resolve(localesPath, locale, 'send.ftl'), 'utf8')
  );
  return [locale, bundle];
}