Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
SNNafi committed May 13, 2024
1 parent 2065d2c commit 6a3073b
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 87 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PR Check

on:
workflow_dispatch:
pull_request:

jobs:
test:
name: Test
uses: ./.github/workflows/test.yml
secrets: inherit
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release to pub.dev

on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:
test:
name: Test
uses: ./.github/workflows/test.yml
secrets: inherit

publish:
needs: [test]
name: Publish
permissions:
id-token: write # This is required for authentication using OIDC
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v3

- uses: dart-lang/setup-dart@v1

- uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Install dependencies
run: dart pub get

- name: code format
run: dart format lib/*/*.dart lib/*.dart

- name: Publish
run: dart pub publish --force
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test

on:
workflow_call:

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
channel: 'stable'

- name: Install packages dependencies
run: flutter pub get

- name: Analyze the project's Dart code
run: flutter analyze

- name: Run tests
run: flutter test

- name: Run tests coverage
run: flutter test --coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.ipr
*.iws
.idea/
.vscode/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
Expand Down
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## [0.0.1]
## 2.0.1

- initial release
- Extend delimiters for csv loader

## 2.0.0

- **BREAKING**: The local `AssetLoader` class deleted, now using the one from
[easy_localization](https://pub.dev/documentation/easy_localization/latest/easy_localization/AssetLoader-class.html) itself.
- **BREAKING**: Depends on [connectivity_plus](https://pub.dev/packages/connectivity_plus) ^4.0.0
and [http](https://pub.dev/packages/http) ^1.0.0.
- Const constructors in:
- `FileAssetLoader`
- `HttpAssetLoader`
- `JsonAssetLoader`
- `TestsAssetLoader`
- `XmlAssetLoader`
- `YamlAssetLoader`
- Fixed deprecations

## 0.0.1

- Initial release.
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Contributing

## Release process

1. Make sure that the changelog is updated

2. Make sure that the version in pubspec.yaml is correct

3. Create a release in the github UI. Name the release like the version, but with a v (3.7.5 -> v3.7.5). Name the tag like the release

4. A pipeline will run and deploy the new version to pub.dev
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies:
#Easy Localization main package
easy_localization: <last_version>

# stable version install from https://pub.dev/packages
# stable version install from https://pub.dev/packages
easy_localization_loader: <last_version>

# Dev version install from git REPO
Expand All @@ -40,10 +40,11 @@ dependencies:

```

2. Change assetLoader and patch
2. Change assetLoader and path

```dart
...void main(){
...
void main(){
runApp(EasyLocalization(
child: MyApp(),
supportedLocales: [Locale('en', 'US'), Locale('ar', 'DZ')],
Expand All @@ -54,4 +55,20 @@ assetLoader: CsvAssetLoader()
...
```

3. All done!.
3. All done!.


### Loaders Specification

#### HttpAssetLoader

In order to use HttpAssetLoader you must provide a path to a folder (i.e. base path) where all your translations are placed like `https://example.com/translations`

Your translations should be created as separate files with `.json` extension. Placing translations as individual files reduces the size of the file to load on application init.
Example:

```
translations/
├── en-US.json
└── uk-UA.json
```
14 changes: 6 additions & 8 deletions lib/easy_localization_loader.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
library easy_localization_loader;

export 'package:easy_localization_loader/src/csv_asset_loader.dart';
export 'package:easy_localization_loader/src/file_asset_loader.dart';
export 'package:easy_localization_loader/src/arb_asset_loader.dart';
export 'package:easy_localization_loader/src/json_asset_loader.dart';
export 'package:easy_localization_loader/src/http_asset_loader.dart';
export 'package:easy_localization_loader/src/csv_asset_loader.dart';
export 'package:easy_localization_loader/src/yaml_asset_loader.dart';
export 'package:easy_localization_loader/src/xml_asset_loader.dart';
export 'package:easy_localization_loader/src/tests_asset_loader.dart';
export 'package:easy_localization_loader/src/json_asset_loader.dart';
export 'package:easy_localization_loader/src/smart_network_asset_loader.dart';
export 'package:easy_localization_loader/src/tests_asset_loader.dart';
export 'package:easy_localization_loader/src/xml_asset_loader.dart';
export 'package:easy_localization_loader/src/yaml_asset_loader.dart';
export 'package:easy_localization_loader/src/arb_asset_loader.dart';
8 changes: 4 additions & 4 deletions lib/src/arb_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import 'dart:ui';

import 'package:flutter/services.dart';

import 'asset_loader.dart';
import 'package:easy_localization/easy_localization.dart';

class ArbAssetLoader extends AssetLoader {
const ArbAssetLoader();

String getLocalePath(String basePath, Locale locale) {
return '$basePath/${localeToString(locale, separator: "-")}.arb';
return '$basePath/${locale.toStringWithSeparator(separator: "-")}.arb';
}

@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
var localePath = getLocalePath(path, locale);
log('easy localization loader: load arb file $localePath');

return jsonDecode(await rootBundle.loadString(localePath));
}
}
Expand All @@ -32,7 +33,6 @@ class ArbSingleAssetLoader extends AssetLoader {
} else {
log('easy localization loader: arb already loaded, read cache');
}

return jsonData![locale.toString()];
}
}
27 changes: 0 additions & 27 deletions lib/src/asset_loader.dart

This file was deleted.

17 changes: 13 additions & 4 deletions lib/src/csv_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ import 'dart:ui';

import 'package:csv/csv.dart';
import 'package:csv/csv_settings_autodetection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';

import 'asset_loader.dart';

//
// load example/resources/langs/langs.csv
//
class CsvAssetLoader extends AssetLoader {
CSVParser? csvParser;
final bool useAutodetect;

CsvAssetLoader({
this.useAutodetect = true,
});

@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
if (csvParser == null) {
log('easy localization loader: load csv file $path');
csvParser = CSVParser(await rootBundle.loadString(path));
csvParser = CSVParser(
await rootBundle.loadString(path),
useAutodetect: useAutodetect,
);
} else {
log('easy localization loader: CSV parser already loaded, read cache');
}
Expand Down Expand Up @@ -60,8 +67,10 @@ class CSVParser {
csvSettingsDetector:
useAutodetect && fieldDelimiter == null && eol == null
? FirstOccurrenceSettingsDetector(
fieldDelimiters: [',', ';', '\t'],
textDelimiters: ['"', "'", '”'],
textEndDelimiters: ['"', "'", '”'],
eols: ['\r\n', '\n'],
fieldDelimiters: [',', '\t'],
)
: null,
);
Expand Down
8 changes: 3 additions & 5 deletions lib/src/file_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import 'dart:developer';
import 'dart:io';
import 'dart:ui';

import 'asset_loader.dart';
import 'package:easy_localization/easy_localization.dart';

//
//
//
//
class FileAssetLoader extends AssetLoader {
const FileAssetLoader();

@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
final file = File(path);
Expand Down
15 changes: 6 additions & 9 deletions lib/src/http_asset_loader.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
//
//
//
//
import 'dart:convert';
import 'dart:developer';
import 'dart:ui';

import 'package:easy_localization/easy_localization.dart';
import 'package:http/http.dart' as http;

import 'asset_loader.dart';

class HttpAssetLoader extends AssetLoader {
const HttpAssetLoader();

@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
log('easy localization loader: load http $path');
try {
var url = Uri.parse(path);
var url = Uri.parse('$path/${locale.toLanguageTag()}.json');
return http
.get(url)
.then((response) => json.decode(response.body.toString()));
.then((response) => json.decode(utf8.decode(response.bodyBytes)));
} catch (e) {
//Catch network exceptions
return Future.value();
return {};
}
}
}
7 changes: 4 additions & 3 deletions lib/src/json_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import 'dart:convert';
import 'dart:developer';
import 'dart:ui';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';

import 'asset_loader.dart';

class JsonAssetLoader extends AssetLoader {
const JsonAssetLoader();

String getLocalePath(String basePath, Locale locale) {
return '$basePath/${localeToString(locale, separator: "-")}.json';
return '$basePath/${locale.toStringWithSeparator(separator: "-")}.json';
}

@override
Expand Down
3 changes: 1 addition & 2 deletions lib/src/smart_network_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import 'dart:convert';
import 'dart:io';
import 'dart:ui';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart' as paths;

import 'package:flutter/services.dart';

import 'asset_loader.dart';

/// ```dart
/// SmartNetworkAssetLoader(
/// assetsPath: 'assets/translations',
Expand Down
5 changes: 3 additions & 2 deletions lib/src/tests_asset_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import 'dart:convert';

import 'dart:ui';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';

import 'asset_loader.dart';

// asset loader to be used when doing integration tests
// default AssetLoader suffers from this issue
// https://github.com/flutter/flutter/issues/44182
class TestsAssetLoader extends AssetLoader {
const TestsAssetLoader();

@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
final byteData = await rootBundle.load(path);
Expand Down
Loading

0 comments on commit 6a3073b

Please sign in to comment.