load static method
Load the project rooted at root (the directory that contains
dialect/). Throws FileSystemException if the directory layout
is wrong; throws FormatException from the parsers if any file is
malformed.
A missing translation file is NOT an error here — missing_keys
reports it. We synthesize an empty ArbFile for the locale so
downstream rules don't have to null-check.
Implementation
static DialectProject load(String root) {
final dialectDir = Directory(p.join(root, 'dialect'));
if (!dialectDir.existsSync()) {
throw FileSystemException('No dialect/ directory found in $root');
}
final configFile = File(p.join(dialectDir.path, 'dialect.yaml'));
if (!configFile.existsSync()) {
throw FileSystemException('Missing dialect/dialect.yaml in $root');
}
final config = DialectConfig.parse(configFile.readAsStringSync());
final sourcePath = p.join(
dialectDir.path,
'source',
'${config.sourceLocale}.arb',
);
final sourceFile = File(sourcePath);
if (!sourceFile.existsSync()) {
throw FileSystemException(
'Missing source ARB at $sourcePath '
'(expected because source_locale is `${config.sourceLocale}` in '
'dialect.yaml).',
);
}
final source = ArbParser.parse(
sourceFile.readAsStringSync(),
sourcePath: sourcePath,
);
final translations = <String, ArbFile>{};
for (final locale in config.targetLocales) {
final tPath = p.join(dialectDir.path, 'translations', '$locale.arb');
final f = File(tPath);
if (!f.existsSync()) {
translations[locale] = ArbFile(
locale: locale,
entries: const [],
sourcePath: tPath,
);
continue;
}
translations[locale] = ArbParser.parse(
f.readAsStringSync(),
sourcePath: tPath,
);
}
final glossary = Glossary.loadFromProjectRoot(root);
return DialectProject(
root: root,
config: config,
source: source,
translations: translations,
glossary: glossary,
);
}