Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
### 0.8.1 (2025-02-18)
### 0.8.2 (2025-05-02)

- [Fix generator issues ('get' keyword in keys)](https://github.com/justprodev/flutter_localizations_ota/pull/7)

### 0.8.1 (2026-04-18)

- [Fix generator issues](https://github.com/justprodev/flutter_localizations_ota/pull/5)

Expand Down
2 changes: 1 addition & 1 deletion lib/src/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Future<void> generate([String path = 'l10n.yaml']) async {
}

if (line.startsWith('String get')) {
final key = line.split('get')[1].split(';')[0].trim();
final key = line.split('get ')[1].split(';')[0].trim();
output.writeln(_generateField(key));
} else {
final key = line.split(' ')[1].split('(').first;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_localizations_ota
description: Over-The-Air updates for Flutter Framework localizations.
version: 0.8.1
version: 0.8.2
repository: https://github.com/justprodev/flutter_localizations_ota

topics:
Expand Down
1 change: 0 additions & 1 deletion test/.gitignore

This file was deleted.

93 changes: 0 additions & 93 deletions test/arb_worker_golden2_test.dart

This file was deleted.

44 changes: 0 additions & 44 deletions test/arb_worker_test.dart

This file was deleted.

File renamed without changes.
File renamed without changes.
128 changes: 128 additions & 0 deletions test/arb_worker_test/arb_worker_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Created by alex@justprodev.com on 13.02.2025.

import 'dart:convert';
import 'dart:io';

// ignore_for_file: avoid_print, avoid_relative_lib_imports

import 'package:flutter_localizations_ota/src/arb_worker/arb_parser.dart';
import 'package:flutter_localizations_ota/src/arb_worker/arb_worker.dart';
import 'package:test/test.dart';

const testDir = 'test/arb_worker_test';

main() {
group('english straightforward working well', () {
final testArb = File('$testDir/arb/app_en.arb').readAsStringSync();
var worker = ArbWorker(parseArbContent(testArb), 'en');

test('retrieves the single key', () {
expect(worker.get('fl_ota_version'), equals('1'));
expect(worker.get('new_test_key'), equals('A new test key'));
});
test('retrieves the correct translation with plurals', () {
expect(worker.get('nMails', {'count': 0, 'name': 'Nico'}), equals('You have no mails, Nico'));
expect(worker.get('nMails', {'count': 1, 'name': 'Nico'}), equals('Nico! You have one mail!'));
expect(worker.get('nMails', {'count': 2, 'name': 'Nico'}), equals('You have two mails, Nico'));
expect(worker.get('nMails', {'count': 4, 'name': 'Nico'}), equals('You have like 4 mails, Nico'));
expect(worker.get('nMails', {'count': 13, 'name': 'Nico'}), equals('You have like 13 mails, Nico'));
expect(worker.get('nMails', {'count': 3456, 'name': 'Nico'}), equals('You have like 3456 mails, Nico'));
});
test('retrieves the correct translation with genders', () {
expect(worker.get('pageHomeBirthday', {'sex': 'male'}), equals('His birthday'));
expect(worker.get('pageHomeBirthday', {'sex': 'female'}), equals('Her birthday'));
expect(worker.get('pageHomeBirthday', {'sex': 'anything'}), equals('The birthday of them'));
expect(worker.get('pageHomeBirthday', {'sex': 'anything else'}), equals('The birthday of them'));
expect(worker.get('pageHomeBirthday', {'sex': 'other'}), equals('The birthday of them'));
});
test('retrieves the correct translation with select', () {
expect(worker.get('trafficLight', {'light': 'red'}), equals('stop'));
expect(worker.get('trafficLight', {'light': 'yellow'}), equals('ready to go'));
expect(worker.get('trafficLight', {'light': 'green'}), equals('go'));
expect(worker.get('trafficLight', {'light': 'ngangong'}), equals('-'));
});

test('order', () {
expect(worker.get('nMails', {'name': 'Nico', 'count': 2}), equals('You have two mails, Nico'));
});
});

// generating test file, writing tests and running them via `flutter test`
test('Compare ARB translator nodes with L10n', () async {
const generatedFileName = 'l10n_test.g.dart';
final nodes = parseArbContent(File('$testDir/arb/app_ru.arb').readAsStringSync());
ArbWorker arbWorker = ArbWorker(nodes, 'ru');

File input = File('$testDir/generated/l10n_ru.dart');
IOSink output = File('$testDir/generated/$generatedFileName').openWrite();

output.writeln('''
import 'l10n_ru.dart';
import 'package:test/test.dart';

void main() {
L10nRu l10n = L10nRu();

test('Test generated l10n', () {
''');

final lines = input.readAsLinesSync();

var testedCallsCount = 0;

// enumerate methods and call it
for (int i = 0; i < lines.length; i++) {
if (lines[i].trimLeft().startsWith("@override")) {
i++;
if (lines[i].trimLeft().startsWith('String get')) {
final key = lines[i].split('get')[1].split('=>')[0].trim();
output.writeln("\t\texpect(l10n.$key, '''${arbWorker.get(key)}''');");
testedCallsCount++;
} else {
final key = lines[i].trimLeft().split(' ')[1].split('(').first;
final params = lines[i].split('(').last.split(')')[0].split(',');

for(int i = 0; i < 5; i++) {
final args = <String, dynamic>{};
final values = <dynamic>[];
for (var param in params) {
final pair = param.trim().split(' ');

if(pair[0] == 'String') {
args[pair[1]] = 'string$i';
values.add('\'${args[pair[1]]}\'');
} else {
args[pair[1]] = i;
values.add(i);
}
}
output.writeln(
"\t\texpect(l10n.$key(${values.join(',')}), '''${arbWorker.get(key, args)}''');",
);
}
testedCallsCount++;
}
}
}

output.writeln('''
});
}
''');

await output.close();

final result = Process.runSync(
Platform.isWindows ? 'flutter.bat' : 'flutter',
['test', '$testDir/generated/$generatedFileName'],
stdoutEncoding: Encoding.getByName('UTF-8'),
stderrEncoding: Encoding.getByName('UTF-8'),
);

print(result.stdout);
print(result.stderr);

expect(result.exitCode, 0);
expect(testedCallsCount, nodes.keys.length);
});
}
File renamed without changes.
File renamed without changes.
48 changes: 0 additions & 48 deletions test/generator_test.dart

This file was deleted.

1 change: 1 addition & 0 deletions test/generator_test/generated/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
l10n_remote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ abstract class L10n {
/// In en, this message translates to:
/// **'{light, select, red{stop} yellow{ready to go} green{go} other{-}}'**
String trafficLight(String light);

String get widgetTitle;

String get getSomeText;
}

class _L10nDelegate extends LocalizationsDelegate<L10n> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ class L10nEn extends L10n {
);
return '$_temp0';
}

@override
String get widgetTitle => 'Widget title';

@override
String get getSomeText => 'Get some text';
}
Loading
Loading