-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:logging/logging.dart'; | ||
import 'package:native_assets_cli/native_assets_cli.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
// implements Builder | ||
class MessageBuilder { | ||
final List<String> arbFiles; | ||
final List<String> locales; | ||
|
||
MessageBuilder({ | ||
required this.arbFiles, | ||
required this.locales, | ||
}); | ||
|
||
Future<void> run({ | ||
required BuildConfig config, | ||
required BuildOutput output, | ||
required Logger? logger, | ||
}) async { | ||
DataAsset fileToAsset(String relativePath) => DataAsset( | ||
package: config.packageName, | ||
name: relativePath, | ||
file: config.packageRoot.resolve(relativePath), | ||
); | ||
|
||
for (final arb in arbFiles) { | ||
final arbNoExtension = p.withoutExtension(arb); | ||
for (final locale in locales) { | ||
final data = p.setExtension(arbNoExtension, '_$locale.json'); | ||
final asset = fileToAsset(data); | ||
if (await File.fromUri(asset.file!).exists()) { | ||
output.addAsset(asset); | ||
} else { | ||
logger?.warning('Could not find messages for locale "$locale" and' | ||
' arb "$arb" at ${asset.file}'); | ||
} | ||
} | ||
} | ||
|
||
output.addDependencies([ | ||
...arbFiles, | ||
'hook/build.dart', | ||
].map(config.packageRoot.resolve)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters