Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/smart-network-loader #34

Merged
merged 5 commits into from
Aug 17, 2022
Merged

feature/smart-network-loader #34

merged 5 commits into from
Aug 17, 2022

Conversation

ariefwijaya
Copy link
Contributor

@ariefwijaya ariefwijaya commented Jun 20, 2022

Purpose

  • add new class SmartNetworkAssetLoader that able to fetch localization using online .json files from provided url.
  • add configurable cache from network assets using Duration(..) class
  • add Failover system to local assets when there is a failure when fetching the online .json and no caches stored
  • inspired by and resolved AssetOrNetworkAssetLoader #30 , HttpAssetLoader() #29 , load from network #17

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

How to Test

Just use this class in the assetLoader attribute of EasyLocalization and configure it as you want

SmartNetworkAssetLoader(
          assetsPath: 'assets/translations',
          localCacheDuration: Duration(days: 1),
          localeUrl: (String localeName) => Constants.appLangUrl,
          timeout: Duration(seconds: 30)
)

Environment

Please define your environment to test this, you can choose multiple options. Put an x in the boxes that apply

  • Production
  • Development
  • Testing
  • Android
  • iOS
Attach your `flutter doctor -v` inside code block:

[✓] Flutter (Channel stable, 2.5.3, on macOS 12.3.1 21E258 darwin-arm, locale en-ID)
    • Flutter version 2.5.3 at /Users/ariefwijaya/fvm/versions/2.5.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (6 months ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2)
    • Android SDK at /Users/ariefwijaya/Library/Android/sdk
    • Platform android-31, build-tools 33.0.0-rc2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.3.1, Build version 13E500a
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2020.3.4)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.38.1

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.127

• No issues found!

Expected Results

  1. able to fetch localization data from provided url, otherwise get data from assetsPath
  2. When the data has been fetched, it can be use even in offline because caches system

@Floul
Copy link

Floul commented Aug 12, 2022

Really waiting for this feature, because we are planning to use a localization management system like Localizely or smth like this.

@ariefwijaya
Copy link
Contributor Author

Really waiting for this feature, because we are planning to use a localization management system like Localizely or smth like this.

I've used this already in our company, you can use my branch first until this PR merged @Floul

@ariefwijaya
Copy link
Contributor Author

@aissat any update on this?

@aissat aissat merged commit 02397cf into aissat:master Aug 17, 2022
@Floul
Copy link

Floul commented Aug 25, 2022

Thank you @ariefwijaya . One more question. I need to pass a token with the http call to get a translation from Localizely. Is there any way to do it with this loader?

@ariefwijaya
Copy link
Contributor Author

Thank you @ariefwijaya . One more question. I need to pass a token with the http call to get a translation from Localizely. Is there any way to do it with this loader?

Not available yet, but we can add it. Please create an issue

@Floul
Copy link

Floul commented Aug 26, 2022

Thank you @ariefwijaya . One more question. I need to pass a token with the http call to get a translation from Localizely. Is there any way to do it with this loader?

Not available yet, but we can add it. Please create an issue

#37 done.

@PavieOlivier
Copy link

Hello,
As I can see , in your description, you are using .Json
We currently have CSVs,
Do we need to convert our CSVs to Json or is it ok to let out files be CSVs?
(considering that our CSVs are kind. of hudge)

@ariefwijaya
Copy link
Contributor Author

Hello,
As I can see , in your description, you are using .Json
We currently have CSVs,
Do we need to convert our CSVs to Json or is it ok to let out files be CSVs?
(considering that our CSVs are kind. of hudge)

For now, we convert csv to json using javascript. Technically, it will download data from online spreadsheet, and convert it to json.

@PavieOlivier
Copy link

For now, we convert csv to json using javascript. Technically, it will download data from online spreadsheet, and convert it to json.

ok ok, thanks :)
I will try to make it work then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AssetOrNetworkAssetLoader
4 participants