├── lib
├── yalo.dart
└── src
│ ├── templates
│ ├── assets_pubspec_template.dart
│ ├── locale_pubspec_template.dart
│ ├── language_template.dart
│ ├── namespace_template.dart
│ ├── intl_template.dart
│ ├── localization_content_template.dart
│ └── parsing_methods.dart
│ ├── utils
│ ├── utils.dart
│ └── assets_scanner.dart
│ ├── constants
│ └── constants.dart
│ ├── assets_saver.dart
│ ├── directory_reader.dart
│ ├── locale_saver.dart
│ ├── locale_generator.dart
│ └── assets_generator.dart
├── example
├── linux
│ ├── .gitignore
│ ├── main.cc
│ ├── flutter
│ │ ├── generated_plugin_registrant.cc
│ │ ├── generated_plugin_registrant.h
│ │ ├── generated_plugins.cmake
│ │ └── CMakeLists.txt
│ ├── my_application.h
│ ├── my_application.cc
│ └── CMakeLists.txt
├── test
│ ├── localization_generator_example.dart.template
│ └── example_app_localization_generator_test.dart
├── assets
│ ├── text
│ │ ├── first.txt
│ │ └── second.txt
│ ├── second.json
│ ├── img
│ │ ├── en.png
│ │ └── ru.png
│ ├── rive
│ │ └── Rig Demo.flr2d
│ └── localization
│ │ ├── de.intl.yaml
│ │ └── en.intl.yaml
├── ios
│ ├── Flutter
│ │ ├── Debug.xcconfig
│ │ ├── Release.xcconfig
│ │ └── AppFrameworkInfo.plist
│ ├── Runner
│ │ ├── Runner-Bridging-Header.h
│ │ ├── Assets.xcassets
│ │ │ ├── LaunchImage.imageset
│ │ │ │ ├── LaunchImage.png
│ │ │ │ ├── LaunchImage@2x.png
│ │ │ │ ├── LaunchImage@3x.png
│ │ │ │ ├── README.md
│ │ │ │ └── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── Icon-App-20x20@1x.png
│ │ │ │ ├── Icon-App-20x20@2x.png
│ │ │ │ ├── Icon-App-20x20@3x.png
│ │ │ │ ├── Icon-App-29x29@1x.png
│ │ │ │ ├── Icon-App-29x29@2x.png
│ │ │ │ ├── Icon-App-29x29@3x.png
│ │ │ │ ├── Icon-App-40x40@1x.png
│ │ │ │ ├── Icon-App-40x40@2x.png
│ │ │ │ ├── Icon-App-40x40@3x.png
│ │ │ │ ├── Icon-App-60x60@2x.png
│ │ │ │ ├── Icon-App-60x60@3x.png
│ │ │ │ ├── Icon-App-76x76@1x.png
│ │ │ │ ├── Icon-App-76x76@2x.png
│ │ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ │ ├── Icon-App-83.5x83.5@2x.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Base.lproj
│ │ │ ├── Main.storyboard
│ │ │ └── LaunchScreen.storyboard
│ │ └── Info.plist
│ ├── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ └── IDEWorkspaceChecks.plist
│ └── .gitignore
├── analysis_options.yml
├── macos
│ ├── Flutter
│ │ ├── Flutter-Debug.xcconfig
│ │ ├── Flutter-Release.xcconfig
│ │ └── GeneratedPluginRegistrant.swift
│ ├── Runner
│ │ ├── Configs
│ │ │ ├── Debug.xcconfig
│ │ │ ├── Release.xcconfig
│ │ │ ├── Warnings.xcconfig
│ │ │ └── AppInfo.xcconfig
│ │ ├── Assets.xcassets
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── app_icon_16.png
│ │ │ │ ├── app_icon_32.png
│ │ │ │ ├── app_icon_64.png
│ │ │ │ ├── app_icon_1024.png
│ │ │ │ ├── app_icon_128.png
│ │ │ │ ├── app_icon_256.png
│ │ │ │ ├── app_icon_512.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Release.entitlements
│ │ ├── DebugProfile.entitlements
│ │ ├── MainFlutterWindow.swift
│ │ └── Info.plist
│ ├── .gitignore
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── web
│ ├── favicon.png
│ ├── icons
│ │ ├── Icon-192.png
│ │ ├── Icon-512.png
│ │ ├── Icon-maskable-192.png
│ │ └── Icon-maskable-512.png
│ ├── manifest.json
│ └── index.html
├── android
│ ├── gradle.properties
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── drawable
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── drawable-v21
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── values
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ └── values-night
│ │ │ │ │ │ └── styles.xml
│ │ │ │ ├── kotlin
│ │ │ │ │ └── com
│ │ │ │ │ │ └── alphamikle
│ │ │ │ │ │ └── yalo
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ └── AndroidManifest.xml
│ │ │ ├── debug
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── profile
│ │ │ │ └── AndroidManifest.xml
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ ├── .gitignore
│ ├── settings.gradle
│ └── build.gradle
├── windows
│ ├── runner
│ │ ├── resources
│ │ │ └── app_icon.ico
│ │ ├── resource.h
│ │ ├── utils.h
│ │ ├── runner.exe.manifest
│ │ ├── flutter_window.h
│ │ ├── CMakeLists.txt
│ │ ├── main.cpp
│ │ ├── utils.cpp
│ │ ├── flutter_window.cpp
│ │ ├── Runner.rc
│ │ ├── win32_window.h
│ │ └── win32_window.cpp
│ ├── flutter
│ │ ├── generated_plugin_registrant.cc
│ │ ├── generated_plugin_registrant.h
│ │ ├── generated_plugins.cmake
│ │ └── CMakeLists.txt
│ ├── .gitignore
│ └── CMakeLists.txt
├── .yalo_locale
│ ├── pubspec.yaml
│ └── lib
│ │ └── lib.dart
├── README.md
├── pubspec.yaml
├── .gitignore
├── analysis_options.yaml
├── .metadata
├── lib
│ └── main.dart
└── pubspec.lock
├── analysis_options.yaml
├── generate.sh
├── .yalo_locale
├── pubspec.yaml
└── lib
│ ├── lib.dart
│ └── src
│ └── locale.dart
├── CHANGELOG.md
├── .metadata
├── pubspec.yaml
├── bin
├── asset.dart
└── loc.dart
├── test
└── localization_generator_test.dart
├── LICENSE
├── .gitignore
├── assets
└── en_intl.yaml
└── pubspec.lock
/lib/yalo.dart:
--------------------------------------------------------------------------------
1 | library yalo;
2 |
--------------------------------------------------------------------------------
/example/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/example/test/localization_generator_example.dart.template:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/assets/text/first.txt:
--------------------------------------------------------------------------------
1 | Hello, it's a first text asset
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
--------------------------------------------------------------------------------
/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/example/analysis_options.yml:
--------------------------------------------------------------------------------
1 | include: package:pedantic/analysis_options.yml
--------------------------------------------------------------------------------
/example/assets/second.json:
--------------------------------------------------------------------------------
1 | {
2 | "hello": "It's a second json asset"
3 | }
--------------------------------------------------------------------------------
/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/example/assets/text/second.txt:
--------------------------------------------------------------------------------
1 | Ooh, this is an asset with exact name, which one of other assets
--------------------------------------------------------------------------------
/example/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/example/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/web/favicon.png
--------------------------------------------------------------------------------
/example/assets/img/en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/assets/img/en.png
--------------------------------------------------------------------------------
/example/assets/img/ru.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/assets/img/ru.png
--------------------------------------------------------------------------------
/example/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/generate.sh:
--------------------------------------------------------------------------------
1 | cd ./example || exit
2 |
3 | flutter pub run yalo:asset
4 | flutter pub run yalo:loc
5 |
--------------------------------------------------------------------------------
/example/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/example/assets/rive/Rig Demo.flr2d:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/assets/rive/Rig Demo.flr2d
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/example/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/dgph
7 | **/xcuserdata/
8 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alphamikle/yalo/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/example/linux/main.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | int main(int argc, char** argv) {
4 | g_autoptr(MyApplication) app = my_application_new();
5 | return g_application_run(G_APPLICATION(app), argc, argv);
6 | }
7 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/app/src/main/kotlin/com/alphamikle/yalo/example/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.alphamikle.yalo.example.example
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 |
10 | void fl_register_plugins(FlPluginRegistry* registry) {
11 | }
12 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 |
10 | void RegisterPlugins(flutter::PluginRegistry* registry) {
11 | }
12 |
--------------------------------------------------------------------------------
/.yalo_locale/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: yalo_locale
2 | description: Locale of app
3 | version: 1.0.0
4 |
5 | environment:
6 | sdk: ">=2.17.0 <3.0.0"
7 |
8 | dependencies:
9 | flutter:
10 | sdk: flutter
11 | flutter_localizations:
12 | sdk: flutter
13 | intl: ^0.17.0
14 |
--------------------------------------------------------------------------------
/example/.yalo_locale/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: yalo_locale
2 | description: Locale of app
3 | version: 1.0.0
4 |
5 | environment:
6 | sdk: ">=2.17.0 <3.0.0"
7 |
8 | dependencies:
9 | flutter:
10 | sdk: flutter
11 | flutter_localizations:
12 | sdk: flutter
13 | intl: ^0.17.0
14 |
--------------------------------------------------------------------------------
/example/macos/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | @NSApplicationMain
5 | class AppDelegate: FlutterAppDelegate {
6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
7 | return true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
7 |
--------------------------------------------------------------------------------
/example/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [3.0.0] - Variables substitution, updated dependencies, formatting of output code, dynamic access to content, references to another languages files
2 | ## [2.0.2] - Update dependencies
3 | ## [2.0.1] - Update dependencies
4 | ## [2.0.0] - Add non-nullable feature
5 | ## [1.0.1] - Fix exports paths
6 | ## [1.0.0] - First release
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/lib/src/templates/assets_pubspec_template.dart:
--------------------------------------------------------------------------------
1 | String assetsPubspecTemplate(String name, String dartSdk) => '''
2 | name: $name
3 | description: Assets of app
4 | version: 1.0.0
5 |
6 | environment:
7 | sdk: "$dartSdk"
8 |
9 | dependencies:
10 | flutter:
11 | sdk: flutter
12 | flutter_localizations:
13 | sdk: flutter
14 | ''';
15 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 216dee60c0cc9449f0b29bcf922974d612263e24
8 | channel: unknown
9 |
10 | project_type: package
11 |
--------------------------------------------------------------------------------
/lib/src/utils/utils.dart:
--------------------------------------------------------------------------------
1 | String capitalize(String? string) {
2 | if (string == null || string.isEmpty) {
3 | return '';
4 | }
5 | return string.substring(0, 1).toUpperCase() + string.substring(1, string.length);
6 | }
7 |
8 | void log(String message, {String? name}) {
9 | print('${name?.isEmpty ?? true ? '' : '[${name!.toUpperCase()}]'} $message');
10 | }
11 |
--------------------------------------------------------------------------------
/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | **/*.keystore
13 | **/*.jks
14 |
--------------------------------------------------------------------------------
/example/macos/Flutter/GeneratedPluginRegistrant.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | import FlutterMacOS
6 | import Foundation
7 |
8 | import shared_preferences_macos
9 |
10 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
11 | SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
12 | }
13 |
--------------------------------------------------------------------------------
/lib/src/templates/locale_pubspec_template.dart:
--------------------------------------------------------------------------------
1 | String localePubspecTemplate(String name, String dartSdk, String intlVersion) => '''
2 | name: $name
3 | description: Locale of app
4 | version: 1.0.0
5 |
6 | environment:
7 | sdk: "$dartSdk"
8 |
9 | dependencies:
10 | flutter:
11 | sdk: flutter
12 | flutter_localizations:
13 | sdk: flutter
14 | intl: $intlVersion
15 | ''';
16 |
--------------------------------------------------------------------------------
/example/.yalo_locale/lib/lib.dart:
--------------------------------------------------------------------------------
1 | library yalo_locale;
2 |
3 | export 'src/locale.dart'
4 | show
5 | Messages,
6 | LocalizationMessages,
7 | localizationsDelegates,
8 | supportedLocales,
9 | App,
10 | Tooltips,
11 | Presidents,
12 | SecondStoryExample,
13 | FirstTabSecondStory,
14 | MainViewFirstTab,
15 | MainView;
16 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/example/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/.yalo_locale/lib/lib.dart:
--------------------------------------------------------------------------------
1 | library yalo_locale;
2 |
3 | export 'src/locale.dart'
4 | show
5 | Messages,
6 | LocalizationMessages,
7 | localizationsDelegates,
8 | supportedLocales,
9 | NamespacedZoneCheckout,
10 | NamespacedZoneInnerNamespacedZone,
11 | NamespacedZone,
12 | App,
13 | CartCheckout,
14 | Cart,
15 | MainScreen;
16 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void fl_register_plugins(FlPluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void RegisterPlugins(flutter::PluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/example/macos/Runner/DebugProfile.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.cs.allow-jit
8 |
9 | com.apple.security.network.server
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/linux/my_application.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_MY_APPLICATION_H_
2 | #define FLUTTER_MY_APPLICATION_H_
3 |
4 | #include
5 |
6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7 | GtkApplication)
8 |
9 | /**
10 | * my_application_new:
11 | *
12 | * Creates a new Flutter-based application.
13 | *
14 | * Returns: a new #MyApplication.
15 | */
16 | MyApplication* my_application_new();
17 |
18 | #endif // FLUTTER_MY_APPLICATION_H_
19 |
--------------------------------------------------------------------------------
/example/macos/Runner/MainFlutterWindow.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | class MainFlutterWindow: NSWindow {
5 | override func awakeFromNib() {
6 | let flutterViewController = FlutterViewController.init()
7 | let windowFrame = self.frame
8 | self.contentViewController = flutterViewController
9 | self.setFrame(windowFrame, display: true)
10 |
11 | RegisterGeneratedPlugins(registry: flutterViewController)
12 |
13 | super.awakeFromNib()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/example/windows/runner/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by Runner.rc
4 | //
5 | #define IDI_APP_ICON 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/lib/src/constants/constants.dart:
--------------------------------------------------------------------------------
1 | const String kInterfaceName = 'LocalizationMessages';
2 | const String kValue = 'value';
3 | const String kDesc = 'desc';
4 | const String kCode = 'code';
5 | const String kHowMany = 'howMany';
6 | const String kZero = 'zero';
7 | const String kOne = 'one';
8 | const String kTwo = 'two';
9 | const String kFew = 'few';
10 | const String kMany = 'many';
11 | const String kOther = 'other';
12 | const String kLocalizationGeneratorLogPrefix = 'LOCALIZATION GENERATOR';
13 | const String kAssetsGeneratorLogPrefix = 'ASSETS GENERATOR';
14 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/example/assets/localization/de.intl.yaml:
--------------------------------------------------------------------------------
1 | app:
2 | title: Yalo app
3 | description: Presidents app
4 |
5 | books:
6 | zero: Hallo, ${user}! Du hast keine Bücher.
7 | one: Hallo, ${user}! Sie haben ein Buch.
8 | two: Hallo, ${user}! Du hast zwei Bücher! Weiter so!
9 | few: Hallo, ${user}! Sie haben ${howMany} Buch! Sehr beeindruckend!
10 | mane: Hallo, toller ${user}! So viele Bücher wie Sie hat niemand sonst!
11 | other: Hallo, ${user}! Sie haben ${howMany} Buch! Sehr beeindruckend!
12 |
13 | tooltips:
14 | increment: Zuwachs
15 |
16 | presidents: ~en.presidents
17 |
18 | mainView: ~en.mainView
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: yalo
2 | description: Yalo (Yaml localizations) - is a package, which give you a simplest way to get localizations from yaml files
3 | version: 3.0.0
4 | homepage: https://github.com/alphamikle/yalo
5 |
6 | environment:
7 | sdk: ">=2.17.0 <3.0.0"
8 | flutter: ">=3.0.0"
9 |
10 | dependencies:
11 | flutter:
12 | sdk: flutter
13 | intl: ^0.17.0
14 | dart_style: ^2.0.2
15 | yaml: ^3.1.0
16 | path: ^1.8.0
17 | analyzer: ^4.1.0
18 |
19 | dev_dependencies:
20 | flutter_test:
21 | sdk: flutter
22 | flutter_lints: ^2.0.1
23 |
24 | flutter:
25 | assets:
26 | - assets/
--------------------------------------------------------------------------------
/bin/asset.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/assets_generator.dart';
2 | import 'package:yalo/src/assets_saver.dart';
3 | import 'package:yalo/src/constants/constants.dart';
4 | import 'package:yalo/src/utils/utils.dart';
5 |
6 | Future main() async {
7 | final int start = DateTime.now().millisecondsSinceEpoch;
8 | final AssetsGenerator generator = AssetsGenerator();
9 | generator.generate();
10 | AssetsSaver().save(generator);
11 | final double end = (DateTime.now().millisecondsSinceEpoch - start) / 1000;
12 | log('Assets generation completed in $end seconds', name: kAssetsGeneratorLogPrefix);
13 | }
14 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # example
2 |
3 | Example for yalo package
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
13 |
14 | For help getting started with Flutter development, view the
15 | [online documentation](https://docs.flutter.dev/), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/Warnings.xcconfig:
--------------------------------------------------------------------------------
1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings
2 | GCC_WARN_UNDECLARED_SELECTOR = YES
3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES
4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE
5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
6 | CLANG_WARN_PRAGMA_PACK = YES
7 | CLANG_WARN_STRICT_PROTOTYPES = YES
8 | CLANG_WARN_COMMA = YES
9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES
10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
12 | GCC_WARN_SHADOW = YES
13 | CLANG_WARN_UNREACHABLE_CODE = YES
14 |
--------------------------------------------------------------------------------
/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: example
2 | description: Example for yalo package
3 | publish_to: 'none'
4 | version: 1.0.0
5 |
6 | environment:
7 | sdk: ">=2.17.0 <3.0.0"
8 | flutter: ">=3.0.0"
9 |
10 | dependencies:
11 | flutter:
12 | sdk: flutter
13 | flutter_localizations:
14 | sdk: flutter
15 | cupertino_icons: ^1.0.2
16 | device_preview: ^1.1.0
17 | intl: ^0.17.0
18 | yalo:
19 | path: ../
20 | yalo_locale:
21 | path: ./.yalo_locale
22 | # yalo_assets:
23 | # path: ./.yalo_assets
24 |
25 | dev_dependencies:
26 | flutter_test:
27 | sdk: flutter
28 | flutter_lints: ^2.0.0
29 |
30 | flutter:
31 | uses-material-design: true
32 |
33 | assets:
34 | - assets/
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/AppInfo.xcconfig:
--------------------------------------------------------------------------------
1 | // Application-level settings for the Runner target.
2 | //
3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
4 | // future. If not, the values below would default to using the project name when this becomes a
5 | // 'flutter create' template.
6 |
7 | // The application's name. By default this is also the title of the Flutter window.
8 | PRODUCT_NAME = example
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = com.alphamikle.yalo.example.example
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.alphamikle.yalo.example. All rights reserved.
15 |
--------------------------------------------------------------------------------
/bin/loc.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/constants/constants.dart';
2 | import 'package:yalo/src/locale_generator.dart';
3 | import 'package:yalo/src/locale_saver.dart';
4 | import 'package:yalo/src/utils/utils.dart';
5 |
6 | Future main() async {
7 | final int start = DateTime.now().millisecondsSinceEpoch;
8 | final LocaleGenerator generator = LocaleGenerator([]);
9 | generator.generate();
10 | LocaleSaver().save(generator);
11 | final double end = (DateTime.now().millisecondsSinceEpoch - start) / 1000;
12 | log(
13 | 'Localizations generation completed in $end seconds with [${generator.languagesCodes.map((String locale) => '"$locale"').join(', ')}] locales',
14 | name: kLocalizationGeneratorLogPrefix,
15 | );
16 | }
17 |
--------------------------------------------------------------------------------
/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.6.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.1.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/example/windows/runner/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_UTILS_H_
2 | #define RUNNER_UTILS_H_
3 |
4 | #include
5 | #include
6 |
7 | // Creates a console for the process, and redirects stdout and stderr to
8 | // it for both the runner and the Flutter library.
9 | void CreateAndAttachConsole();
10 |
11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
12 | // encoded in UTF-8. Returns an empty std::string on failure.
13 | std::string Utf8FromUtf16(const wchar_t* utf16_string);
14 |
15 | // Gets the command line arguments passed in as a std::vector,
16 | // encoded in UTF-8. Returns an empty std::vector on failure.
17 | std::vector GetCommandLineArguments();
18 |
19 | #endif // RUNNER_UTILS_H_
20 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
9 | )
10 |
11 | set(PLUGIN_BUNDLED_LIBRARIES)
12 |
13 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18 | endforeach(plugin)
19 |
20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23 | endforeach(ffi_plugin)
24 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
9 | )
10 |
11 | set(PLUGIN_BUNDLED_LIBRARIES)
12 |
13 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18 | endforeach(plugin)
19 |
20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23 | endforeach(ffi_plugin)
24 |
--------------------------------------------------------------------------------
/example/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 9.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/lib/src/templates/language_template.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/constants/constants.dart';
2 | import 'package:yalo/src/templates/localization_content_template.dart';
3 |
4 | class LanguageTemplate extends LocalizationContentTemplate {
5 | LanguageTemplate({
6 | required super.title,
7 | required super.isFirst,
8 | }) : super(lang: title);
9 |
10 | @override
11 | String get start => '''
12 | class $title extends $kInterfaceName {
13 | Map get _contentMap => {
14 | ''';
15 |
16 | @override
17 | String get interfaceStart => '''
18 | abstract class $kInterfaceName {
19 | T getContent(String key);
20 | ''';
21 |
22 | @override
23 | String toString() {
24 | String result = namespaces;
25 | if (isFirst) {
26 | result += interfaceStart + interface + end;
27 | }
28 | return result + start + contentMap + contentMapEnd + contentMapGetter + messages + end;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .packages
31 | .pub-cache/
32 | .pub/
33 | /build/
34 |
35 | # Web related
36 | lib/generated_plugin_registrant.dart
37 |
38 | # Symbolication related
39 | app.*.symbols
40 |
41 | # Obfuscation related
42 | app.*.map.json
43 |
44 | # Android Studio will place build artifacts here
45 | /android/app/debug
46 | /android/app/profile
47 | /android/app/release
48 |
--------------------------------------------------------------------------------
/example/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "short_name": "example",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "Example for yalo package",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | },
22 | {
23 | "src": "icons/Icon-maskable-192.png",
24 | "sizes": "192x192",
25 | "type": "image/png",
26 | "purpose": "maskable"
27 | },
28 | {
29 | "src": "icons/Icon-maskable-512.png",
30 | "sizes": "512x512",
31 | "type": "image/png",
32 | "purpose": "maskable"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/example/windows/runner/flutter_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_FLUTTER_WINDOW_H_
2 | #define RUNNER_FLUTTER_WINDOW_H_
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "win32_window.h"
10 |
11 | // A window that does nothing but host a Flutter view.
12 | class FlutterWindow : public Win32Window {
13 | public:
14 | // Creates a new FlutterWindow hosting a Flutter view running |project|.
15 | explicit FlutterWindow(const flutter::DartProject& project);
16 | virtual ~FlutterWindow();
17 |
18 | protected:
19 | // Win32Window:
20 | bool OnCreate() override;
21 | void OnDestroy() override;
22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
23 | LPARAM const lparam) noexcept override;
24 |
25 | private:
26 | // The project to run.
27 | flutter::DartProject project_;
28 |
29 | // The Flutter instance hosted by this window.
30 | std::unique_ptr flutter_controller_;
31 | };
32 |
33 | #endif // RUNNER_FLUTTER_WINDOW_H_
34 |
--------------------------------------------------------------------------------
/test/localization_generator_test.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:flutter_test/flutter_test.dart';
4 | import 'package:path/path.dart' as path;
5 | import 'package:yalo/src/locale_generator.dart';
6 | import 'package:yalo/src/locale_saver.dart';
7 |
8 | void main() {
9 | group('Localization generator I', () {
10 | test('Test of localization generation', () async {
11 | final LocaleGenerator generator = LocaleGenerator([]);
12 | generator.generate();
13 | final LocaleOutput content = LocaleSaver().save(generator);
14 |
15 | final File exampleFile = File(path.join(path.current, 'test', 'localization_generator_example.dart.template'));
16 | final File outputFile = File(path.join(path.current, 'test', 'localization_generator_output.dart.template'));
17 | final File checkFile = File(path.join(path.current, 'test', 'localization_generator_output.dart'));
18 | outputFile.writeAsStringSync(content.localizationFile);
19 | checkFile.writeAsStringSync(content.localizationFile);
20 |
21 | expect(outputFile.readAsStringSync(), exampleFile.readAsStringSync());
22 | });
23 | });
24 | }
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Mikhail Alpha
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/example/test/example_app_localization_generator_test.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:flutter_test/flutter_test.dart';
4 | import 'package:path/path.dart' as path;
5 | import 'package:yalo/src/locale_generator.dart';
6 | import 'package:yalo/src/locale_saver.dart';
7 |
8 | void main() {
9 | group('Localization generator of example app I', () {
10 | test('Test of localization generation', () async {
11 | final LocaleGenerator generator = LocaleGenerator([]);
12 | generator.generate();
13 | final LocaleOutput content = LocaleSaver().save(generator);
14 |
15 | final File exampleFile = File(path.join(path.current, 'test', 'localization_generator_example.dart.template'));
16 | final File outputFile = File(path.join(path.current, 'test', 'localization_generator_output.dart.template'));
17 | final File checkFile = File(path.join(path.current, 'test', 'localization_generator_output.dart'));
18 | outputFile.writeAsStringSync(content.localizationFile);
19 | checkFile.writeAsStringSync(content.localizationFile);
20 |
21 | expect(outputFile.readAsStringSync(), exampleFile.readAsStringSync());
22 | });
23 | });
24 | }
25 |
--------------------------------------------------------------------------------
/example/macos/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | $(PRODUCT_COPYRIGHT)
27 | NSMainNibFile
28 | MainMenu
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/example/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 | project(runner LANGUAGES CXX)
3 |
4 | # Define the application target. To change its name, change BINARY_NAME in the
5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6 | # work.
7 | #
8 | # Any new source files that you add to the application should be added here.
9 | add_executable(${BINARY_NAME} WIN32
10 | "flutter_window.cpp"
11 | "main.cpp"
12 | "utils.cpp"
13 | "win32_window.cpp"
14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
15 | "Runner.rc"
16 | "runner.exe.manifest"
17 | )
18 |
19 | # Apply the standard set of build settings. This can be removed for applications
20 | # that need different build settings.
21 | apply_standard_settings(${BINARY_NAME})
22 |
23 | # Disable Windows macros that collide with C++ standard library functions.
24 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
25 |
26 | # Add dependency libraries and include directories. Add any application-specific
27 | # dependencies here.
28 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
29 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
30 |
31 | # Run the Flutter tool portions of the build. This must not be removed.
32 | add_dependencies(${BINARY_NAME} flutter_assemble)
33 |
--------------------------------------------------------------------------------
/example/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_window.h"
6 | #include "utils.h"
7 |
8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9 | _In_ wchar_t *command_line, _In_ int show_command) {
10 | // Attach to console when present (e.g., 'flutter run') or create a
11 | // new console when running with a debugger.
12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
13 | CreateAndAttachConsole();
14 | }
15 |
16 | // Initialize COM, so that it is available for use in the library and/or
17 | // plugins.
18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
19 |
20 | flutter::DartProject project(L"data");
21 |
22 | std::vector command_line_arguments =
23 | GetCommandLineArguments();
24 |
25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
26 |
27 | FlutterWindow window(project);
28 | Win32Window::Point origin(10, 10);
29 | Win32Window::Size size(1280, 720);
30 | if (!window.CreateAndShow(L"example", origin, size)) {
31 | return EXIT_FAILURE;
32 | }
33 | window.SetQuitOnClose(true);
34 |
35 | ::MSG msg;
36 | while (::GetMessage(&msg, nullptr, 0, 0)) {
37 | ::TranslateMessage(&msg);
38 | ::DispatchMessage(&msg);
39 | }
40 |
41 | ::CoUninitialize();
42 | return EXIT_SUCCESS;
43 | }
44 |
--------------------------------------------------------------------------------
/example/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at
17 | # https://dart-lang.github.io/linter/lints/index.html.
18 | #
19 | # Instead of disabling a lint rule for the entire project in the
20 | # section below, it can also be suppressed for a single line of code
21 | # or a specific dart file by using the `// ignore: name_of_lint` and
22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23 | # producing the lint.
24 | rules:
25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27 |
28 | # Additional information about this file can be found at
29 | # https://dart.dev/guides/language/analysis-options
30 |
--------------------------------------------------------------------------------
/lib/src/assets_saver.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:path/path.dart' as path;
4 | import 'package:yalo/src/assets_generator.dart';
5 | import 'package:yalo/src/templates/assets_pubspec_template.dart';
6 |
7 | class AssetsSaver {
8 | late String packageName;
9 | late String dartSdk;
10 | late String packagePath;
11 | late AssetsGenerator generator;
12 |
13 | void save(AssetsGenerator generator) {
14 | this.generator = generator;
15 | initPackageSettings();
16 | final Directory dir = Directory(packagePath);
17 | if (!dir.existsSync()) {
18 | dir.createSync(recursive: true);
19 | }
20 | final String libPath = path.join(packagePath, 'lib');
21 | final Directory libDir = Directory(libPath);
22 | if (!libDir.existsSync()) {
23 | libDir.createSync(recursive: true);
24 | }
25 | final String srcPath = path.join(libPath, 'src');
26 | final Directory srcDir = Directory(srcPath);
27 | if (!srcDir.existsSync()) {
28 | srcDir.createSync(recursive: true);
29 | }
30 | final File localeFile = File(path.join(srcPath, 'assets.dart'));
31 | localeFile.writeAsStringSync(generator.template);
32 | final File libFile = File(path.join(libPath, 'lib.dart'));
33 | libFile.writeAsStringSync(generator.libExporter);
34 | final File pubspecFile = File(path.join(packagePath, 'pubspec.yaml'));
35 | pubspecFile.writeAsStringSync(assetsPubspecTemplate(packageName, dartSdk));
36 | }
37 |
38 | void initPackageSettings() {
39 | packageName = 'yalo_assets';
40 | dartSdk = generator.scanner.dartSdk ?? '>=2.17.0';
41 | packagePath = path.join(generator.path, '.$packageName');
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "16x16",
5 | "idiom" : "mac",
6 | "filename" : "app_icon_16.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "16x16",
11 | "idiom" : "mac",
12 | "filename" : "app_icon_32.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "32x32",
17 | "idiom" : "mac",
18 | "filename" : "app_icon_32.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "32x32",
23 | "idiom" : "mac",
24 | "filename" : "app_icon_64.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "128x128",
29 | "idiom" : "mac",
30 | "filename" : "app_icon_128.png",
31 | "scale" : "1x"
32 | },
33 | {
34 | "size" : "128x128",
35 | "idiom" : "mac",
36 | "filename" : "app_icon_256.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "256x256",
41 | "idiom" : "mac",
42 | "filename" : "app_icon_256.png",
43 | "scale" : "1x"
44 | },
45 | {
46 | "size" : "256x256",
47 | "idiom" : "mac",
48 | "filename" : "app_icon_512.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "512x512",
53 | "idiom" : "mac",
54 | "filename" : "app_icon_512.png",
55 | "scale" : "1x"
56 | },
57 | {
58 | "size" : "512x512",
59 | "idiom" : "mac",
60 | "filename" : "app_icon_1024.png",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/lib/src/templates/namespace_template.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/templates/localization_content_template.dart';
2 | import 'package:yalo/src/templates/parsing_methods.dart';
3 | import 'package:yalo/src/utils/utils.dart';
4 | import 'package:yaml/yaml.dart';
5 |
6 | class NamespaceTemplate extends LocalizationContentTemplate {
7 | NamespaceTemplate({
8 | required super.title,
9 | required super.lang,
10 | required this.contents,
11 | this.parent = '',
12 | super.isFirst = false,
13 | });
14 |
15 | final YamlMap contents;
16 | final String parent;
17 |
18 | String get capitalizedTitle => capitalize(title);
19 | String get capitalizedFullTitle => capitalize(parent) + capitalizedTitle;
20 |
21 | @override
22 | String get interfaceStart => '''
23 | abstract class $capitalizedFullTitle {
24 | T getContent(String key);
25 | ''';
26 |
27 | @override
28 | String get start => '''
29 | class $lang$capitalizedFullTitle extends $capitalizedFullTitle {
30 | Map get _contentMap => {
31 | ''';
32 |
33 | void _generate() {
34 | final List entries = contents.entries.toList();
35 | for (MapEntry entry in entries) {
36 | final String code = entry.key as String;
37 | final dynamic value = entry.value;
38 | addMessageToLocalizationContentTemplate(value, code, this);
39 | }
40 | }
41 |
42 | @override
43 | String toString() {
44 | _generate();
45 | String result = namespaces;
46 | if (isFirst) {
47 | result += interfaceStart + interface + end;
48 | }
49 | interfaces.add(capitalizedFullTitle);
50 | return result + start + contentMap + contentMapEnd + contentMapGetter + messages + end;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled.
5 |
6 | version:
7 | revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
8 | channel: stable
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
17 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
18 | - platform: android
19 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
20 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
21 | - platform: ios
22 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
23 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
24 | - platform: linux
25 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
26 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
27 | - platform: macos
28 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
29 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
30 | - platform: web
31 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
32 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
33 | - platform: windows
34 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
35 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
36 |
37 | # User provided section
38 |
39 | # List of Local paths (relative to this file) that should be
40 | # ignored by the migrate tool.
41 | #
42 | # Files that are not part of the templates will be ignored by default.
43 | unmanaged_files:
44 | - 'lib/main.dart'
45 | - 'ios/Runner.xcodeproj/project.pbxproj'
46 |
--------------------------------------------------------------------------------
/example/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleDisplayName
8 | Example
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | example
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(FLUTTER_BUILD_NUMBER)
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIMainStoryboardFile
30 | Main
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | UIViewControllerBasedStatusBarAppearance
45 |
46 | CADisableMinimumFrameDurationOnPhone
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | .dart_tool/
26 | .flutter-plugins
27 | .flutter-plugins-dependencies
28 | .packages
29 | .pub-cache/
30 | .pub/
31 | build/
32 |
33 | # Android related
34 | **/android/**/gradle-wrapper.jar
35 | **/android/.gradle
36 | **/android/captures/
37 | **/android/gradlew
38 | **/android/gradlew.bat
39 | **/android/local.properties
40 | **/android/**/GeneratedPluginRegistrant.java
41 |
42 | # iOS/XCode related
43 | **/ios/**/*.mode1v3
44 | **/ios/**/*.mode2v3
45 | **/ios/**/*.moved-aside
46 | **/ios/**/*.pbxuser
47 | **/ios/**/*.perspectivev3
48 | **/ios/**/*sync/
49 | **/ios/**/.sconsign.dblite
50 | **/ios/**/.tags*
51 | **/ios/**/.vagrant/
52 | **/ios/**/DerivedData/
53 | **/ios/**/Icon?
54 | **/ios/**/Pods/
55 | **/ios/**/.symlinks/
56 | **/ios/**/profile
57 | **/ios/**/xcuserdata
58 | **/ios/.generated/
59 | **/ios/Flutter/App.framework
60 | **/ios/Flutter/Flutter.framework
61 | **/ios/Flutter/Flutter.podspec
62 | **/ios/Flutter/Generated.xcconfig
63 | **/ios/Flutter/app.flx
64 | **/ios/Flutter/app.zip
65 | **/ios/Flutter/flutter_assets/
66 | **/ios/Flutter/flutter_export_environment.sh
67 | **/ios/ServiceDefinitions.json
68 | **/ios/Runner/GeneratedPluginRegistrant.*
69 |
70 | # Exceptions to above rules.
71 | !**/ios/**/default.mode1v3
72 | !**/ios/**/default.mode2v3
73 | !**/ios/**/default.pbxuser
74 | !**/ios/**/default.perspectivev3
75 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
76 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
15 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/example/assets/localization/en.intl.yaml:
--------------------------------------------------------------------------------
1 | app:
2 | title: Yalo app
3 | description: Presidents app
4 |
5 | books:
6 | zero: Hello, ${user}! You have no books.
7 | one: Hello, ${user}! You have a one book.
8 | two: Hello, ${user}! You have two books! Keep it up!
9 | few: Hello, ${user}! You have ${howMany} books! Very impressive!
10 | mane: Hello, Great ${user}! As many books as you have, no one else has!
11 | other: Hello, ${user}! You have ${howMany} books! Very impressive!
12 |
13 | tooltips:
14 | increment: Increment
15 |
16 | presidents:
17 | p1: George Washington
18 | p2: John Adams
19 | p3: Thomas Jefferson
20 | p4: James Madison
21 | p5: James Monroe
22 | p6: John Quincy Adams
23 | p7: Andrew Jackson
24 | p8: Martin Van Buren
25 | p9: William Henry Harrison
26 | p10: John Tyler
27 | p11: James K. Polk
28 | p12: Zachary Taylor
29 | p13: Millard Fillmore
30 | p14: Franklin Pierce
31 | p15: James Buchanan
32 | p16: Abraham Lincoln
33 | p17: Andrew Johnson
34 | p18: Ulysses S. Grant
35 | p19: Rutherford B. Hayes
36 | p20: James A. Garfield
37 | p21: Chester A. Arthur
38 | p22: Grover Cleveland
39 | p23: Benjamin Harrison
40 | p24: Grover Cleveland
41 | p25: William McKinley
42 | p26: Theodore Roosevelt
43 | p27: William H. Taft
44 | p28: Woodrow Wilson
45 | p29: Warren G. Harding
46 | p30: Calvin Coolidge
47 | p31: Herbert C. Hoover
48 | p32: Franklin D. Roosevelt
49 | p33: Harry S. Truman
50 | p34: Dwight D. Eisenhower
51 | p35: John F. Kennedy
52 | p36: Lyndon B. Johnson
53 | p37: Richard M. Nixon
54 | p38: Gerald R. Ford
55 | p39: James Earl Carter
56 | p40: Ronald Reagan
57 | p41: George Bush
58 | p42: William J. Clinton
59 | p43: George W. Bush
60 | p44: Barack H. Obama
61 | p45: Donald J. Trump
62 | p46: Joseph R. Biden, Jr.
63 |
64 | mainView:
65 | firstTab:
66 | secondStory:
67 | example:
68 | title: This is a title
69 | description: This is a description
--------------------------------------------------------------------------------
/example/windows/runner/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | void CreateAndAttachConsole() {
11 | if (::AllocConsole()) {
12 | FILE *unused;
13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
14 | _dup2(_fileno(stdout), 1);
15 | }
16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
17 | _dup2(_fileno(stdout), 2);
18 | }
19 | std::ios::sync_with_stdio();
20 | FlutterDesktopResyncOutputStreams();
21 | }
22 | }
23 |
24 | std::vector GetCommandLineArguments() {
25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
26 | int argc;
27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
28 | if (argv == nullptr) {
29 | return std::vector();
30 | }
31 |
32 | std::vector command_line_arguments;
33 |
34 | // Skip the first argument as it's the binary name.
35 | for (int i = 1; i < argc; i++) {
36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
37 | }
38 |
39 | ::LocalFree(argv);
40 |
41 | return command_line_arguments;
42 | }
43 |
44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) {
45 | if (utf16_string == nullptr) {
46 | return std::string();
47 | }
48 | int target_length = ::WideCharToMultiByte(
49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50 | -1, nullptr, 0, nullptr, nullptr);
51 | std::string utf8_string;
52 | if (target_length == 0 || target_length > utf8_string.max_size()) {
53 | return utf8_string;
54 | }
55 | utf8_string.resize(target_length);
56 | int converted_length = ::WideCharToMultiByte(
57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
58 | -1, utf8_string.data(),
59 | target_length, nullptr, nullptr);
60 | if (converted_length == 0) {
61 | return std::string();
62 | }
63 | return utf8_string;
64 | }
65 |
--------------------------------------------------------------------------------
/lib/src/directory_reader.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:analyzer/dart/element/element.dart' as el;
4 | import 'package:path/path.dart' as p;
5 | import 'package:yalo/src/utils/assets_scanner.dart';
6 | import 'package:yaml/yaml.dart';
7 |
8 | mixin DirectoryReader {
9 | final Map> _assetsFoldersWatchers = {};
10 |
11 | late el.Element prevElement;
12 | bool isWatchersAssigned = false;
13 | late String path;
14 | late YamlList _assetsFolders;
15 |
16 | final RegExp _diskWord = RegExp(r'^[a-zA-Z]+:');
17 |
18 | String getOnlyAssetFileName(String assetFileNameWithPath) {
19 | assetFileNameWithPath = assetFileNameWithPath.replaceAll(RegExp(r'\\'), '/');
20 | assetFileNameWithPath = assetFileNameWithPath.replaceAll(RegExp(r'^.*/'), '');
21 | return assetFileNameWithPath;
22 | }
23 |
24 | void scanAssets(AssetsScanner scanner) {
25 | path = scanner.path;
26 | _assetsFolders = scanner.assetsFolders;
27 | }
28 |
29 | Set getAssetDirectoryFiles() {
30 | final Set tempAssetsFiles = {};
31 | for (String assetFolder in _assetsFolders) {
32 | final String dirPath = p.join(path, assetFolder);
33 | final Directory assetDirectory = Directory(dirPath);
34 | if (!_assetsFoldersWatchers.containsKey(dirPath)) {
35 | _assetsFoldersWatchers[dirPath] = assetDirectory.watch(recursive: true);
36 | }
37 | final List folderFiles = assetDirectory.listSync(recursive: true).whereType().toList();
38 | final String unixPath = path.replaceFirst(_diskWord, '').replaceAll(r'\', '/');
39 | tempAssetsFiles.addAll(folderFiles.map((FileSystemEntity fileEntity) {
40 | final String unixFilePath = fileEntity.path.replaceFirst(_diskWord, '').replaceAll(r'\', '/');
41 | final result = unixFilePath.replaceFirst(RegExp('$unixPath/'), '');
42 | return result;
43 | }).where((String fileName) => !fileName.contains('/.')));
44 | }
45 | return tempAssetsFiles;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/example/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | example
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/lib/src/utils/assets_scanner.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:yaml/yaml.dart';
4 |
5 | const kFlutter = 'flutter';
6 | const kAssets = 'assets';
7 | const kDependencies = 'dependencies';
8 | const kIntl = 'intl';
9 | const kEnv = 'environment';
10 | const kSdk = 'sdk';
11 |
12 | class AssetsScanner {
13 | late Directory _curDir;
14 | late String _path;
15 | late List _files;
16 | late FileSystemEntity _pubspecEntity;
17 | late File _pubspecFile;
18 | late YamlMap _pubspecContent;
19 | YamlMap? _flutter;
20 | YamlList? _assetsFolders;
21 |
22 | String get path => _path;
23 |
24 | YamlList get assetsFolders => _assetsFolders!;
25 |
26 | YamlMap? get _dependencies => _pubspecContent[kDependencies];
27 |
28 | String? get intlVersion => _dependencies == null ? null : _dependencies![kIntl];
29 |
30 | String? get dartSdk => _pubspecContent[kEnv][kSdk];
31 |
32 | AssetsScanner() {
33 | _curDir = Directory.current;
34 | _path = _curDir.path;
35 | _files = _curDir.listSync();
36 | _pubspecEntity = _files.firstWhere(
37 | (FileSystemEntity fileEntity) => fileEntity.path.contains(RegExp(r'pubspec.ya?ml$')),
38 | orElse: () => _exception('pubspec file'));
39 | _pubspecFile = File(_pubspecEntity.path);
40 | _pubspecContent = loadYaml(_pubspecFile.readAsStringSync());
41 | _flutter = _pubspecContent[kFlutter];
42 | if (_flutter == null) {
43 | _exception('"flutter" section in pubspec');
44 | }
45 | _assetsFolders = _flutter![kAssets];
46 | if (_assetsFolders == null || _assetsFolders!.isEmpty) {
47 | throw Exception('''
48 | Not found "assets" block in pubspec.yaml file or this block is empty. Please, add at least a one folder to assets block like that:
49 | pubspec.yaml
50 | #...
51 | flutter:
52 | #...
53 | assets: <-- 1
54 | - assets/ <-- 2
55 | #...
56 | ''');
57 | }
58 | }
59 |
60 | _exception(String what) {
61 | throw Exception('Not found $what in $_path directory');
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/example/windows/runner/flutter_window.cpp:
--------------------------------------------------------------------------------
1 | #include "flutter_window.h"
2 |
3 | #include
4 |
5 | #include "flutter/generated_plugin_registrant.h"
6 |
7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8 | : project_(project) {}
9 |
10 | FlutterWindow::~FlutterWindow() {}
11 |
12 | bool FlutterWindow::OnCreate() {
13 | if (!Win32Window::OnCreate()) {
14 | return false;
15 | }
16 |
17 | RECT frame = GetClientArea();
18 |
19 | // The size here must match the window dimensions to avoid unnecessary surface
20 | // creation / destruction in the startup path.
21 | flutter_controller_ = std::make_unique(
22 | frame.right - frame.left, frame.bottom - frame.top, project_);
23 | // Ensure that basic setup of the controller was successful.
24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25 | return false;
26 | }
27 | RegisterPlugins(flutter_controller_->engine());
28 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
29 | return true;
30 | }
31 |
32 | void FlutterWindow::OnDestroy() {
33 | if (flutter_controller_) {
34 | flutter_controller_ = nullptr;
35 | }
36 |
37 | Win32Window::OnDestroy();
38 | }
39 |
40 | LRESULT
41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
42 | WPARAM const wparam,
43 | LPARAM const lparam) noexcept {
44 | // Give Flutter, including plugins, an opportunity to handle window messages.
45 | if (flutter_controller_) {
46 | std::optional result =
47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
48 | lparam);
49 | if (result) {
50 | return *result;
51 | }
52 | }
53 |
54 | switch (message) {
55 | case WM_FONTCHANGE:
56 | flutter_controller_->engine()->ReloadSystemFonts();
57 | break;
58 | }
59 |
60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
61 | }
62 |
--------------------------------------------------------------------------------
/lib/src/locale_saver.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:dart_style/dart_style.dart';
4 | import 'package:path/path.dart' as path;
5 | import 'package:yalo/src/locale_generator.dart';
6 | import 'package:yalo/src/templates/locale_pubspec_template.dart';
7 |
8 | class LocaleOutput {
9 | const LocaleOutput({
10 | required this.localizationFile,
11 | required this.libraryFile,
12 | required this.pubspecFile,
13 | });
14 |
15 | final String localizationFile;
16 | final String libraryFile;
17 | final String pubspecFile;
18 | }
19 |
20 | class LocaleSaver {
21 | late String packageName;
22 | late String dartSdk;
23 | late String intlVersion;
24 | late String packagePath;
25 | late LocaleGenerator generator;
26 |
27 | LocaleOutput save(LocaleGenerator generator) {
28 | this.generator = generator;
29 | initPackageSettings();
30 | final Directory dir = Directory(packagePath);
31 | if (!dir.existsSync()) {
32 | dir.createSync(recursive: true);
33 | }
34 | final String libPath = path.join(packagePath, 'lib');
35 | final Directory libDir = Directory(libPath);
36 | if (!libDir.existsSync()) {
37 | libDir.createSync(recursive: true);
38 | }
39 | final String srcPath = path.join(libPath, 'src');
40 | final Directory srcDir = Directory(srcPath);
41 | if (!srcDir.existsSync()) {
42 | srcDir.createSync(recursive: true);
43 | }
44 | final File localizationFile = File(path.join(srcPath, 'locale.dart'));
45 | final DartFormatter formatter = DartFormatter(pageWidth: 120);
46 | localizationFile.writeAsStringSync(formatter.format(generator.localizationCode));
47 | final File libraryFile = File(path.join(libPath, 'lib.dart'));
48 | libraryFile.writeAsStringSync(formatter.format(generator.generateLibrary()));
49 | final File pubspecFile = File(path.join(packagePath, 'pubspec.yaml'));
50 | pubspecFile.writeAsStringSync(localePubspecTemplate(packageName, dartSdk, intlVersion));
51 | return LocaleOutput(
52 | localizationFile: localizationFile.readAsStringSync(),
53 | libraryFile: libraryFile.readAsStringSync(),
54 | pubspecFile: pubspecFile.readAsStringSync(),
55 | );
56 | }
57 |
58 | void initPackageSettings() {
59 | packageName = 'yalo_locale';
60 | dartSdk = generator.scanner.dartSdk ?? '>=2.17.0';
61 | intlVersion = generator.scanner.intlVersion ?? '0.17.0';
62 | packagePath = path.join(generator.path, '.$packageName');
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion flutter.compileSdkVersion
30 | ndkVersion flutter.ndkVersion
31 |
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 |
37 | kotlinOptions {
38 | jvmTarget = '1.8'
39 | }
40 |
41 | sourceSets {
42 | main.java.srcDirs += 'src/main/kotlin'
43 | }
44 |
45 | defaultConfig {
46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
47 | applicationId "com.alphamikle.yalo.example.example"
48 | // You can update the following values to match your application needs.
49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
50 | minSdkVersion flutter.minSdkVersion
51 | targetSdkVersion flutter.targetSdkVersion
52 | versionCode flutterVersionCode.toInteger()
53 | versionName flutterVersionName
54 | }
55 |
56 | buildTypes {
57 | release {
58 | // TODO: Add your own signing config for the release build.
59 | // Signing with the debug keys for now, so `flutter run --release` works.
60 | signingConfig signingConfigs.debug
61 | }
62 | }
63 | }
64 |
65 | flutter {
66 | source '../..'
67 | }
68 |
69 | dependencies {
70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
71 | }
72 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/lib/src/templates/intl_template.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/constants/constants.dart';
2 | import 'package:yalo/src/templates/language_template.dart';
3 |
4 | class IntlTemplate {
5 | IntlTemplate(this._title);
6 |
7 | final String _title;
8 |
9 | String _templateMapBody = '';
10 |
11 | String _languageClasses = '';
12 |
13 | String get _dependencies => '''
14 | import 'package:flutter_localizations/flutter_localizations.dart';
15 | import 'package:flutter/widgets.dart';
16 | import 'package:intl/intl.dart';
17 |
18 | ''';
19 |
20 | String get _templatesMapStart => '''
21 | final Map _languageMap = {
22 | ''';
23 |
24 | String get _templatesMapEnd => '''
25 | };\n
26 | ''';
27 |
28 | String get _start => '''
29 | class $_title extends LocalizationsDelegate<$kInterfaceName> {
30 | @override
31 | bool isSupported(Locale locale) => _languageMap.keys.contains(locale.languageCode);
32 |
33 | @override
34 | Future<$kInterfaceName> load(Locale locale) async {
35 | Intl.defaultLocale = locale.countryCode == null ? locale.languageCode : locale.toString();
36 | return _languageMap[locale.languageCode]!;
37 | }
38 |
39 | @override
40 | bool shouldReload(LocalizationsDelegate<$kInterfaceName> old) => false;\n
41 | ''';
42 |
43 | String get _end => '''
44 | }\n
45 | ''';
46 |
47 | String get _messagesUtil => '''
48 | class Messages {
49 | static $kInterfaceName of(BuildContext context) => Localizations.of(context, $kInterfaceName);
50 |
51 | $_staticMethods
52 | }
53 |
54 | final List localizationsDelegates = [$_title(), ...GlobalMaterialLocalizations.delegates];\n
55 | ''';
56 |
57 | String _staticMethods = '';
58 |
59 | String _supportedLocales = 'const List supportedLocales = [\n';
60 |
61 | String get _supportedLocalesEnd => '];';
62 |
63 | String get template {
64 | return _dependencies +
65 | _languageClasses +
66 | _start +
67 | _templatesMapStart +
68 | _templateMapBody +
69 | _templatesMapEnd +
70 | _end +
71 | _messagesUtil +
72 | _supportedLocales +
73 | _supportedLocalesEnd;
74 | }
75 |
76 | void addLanguage(String code, LanguageTemplate languageTemplate) {
77 | _languageClasses += languageTemplate.toString();
78 | _templateMapBody += '''
79 | '$code': ${languageTemplate.title}(),
80 | ''';
81 | _staticMethods += '''
82 | static $kInterfaceName get $code => $_title()._languageMap['$code']!;
83 | ''';
84 | _supportedLocales += '''
85 | Locale('$code'),
86 | ''';
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:device_preview/device_preview.dart';
2 | import 'package:flutter/foundation.dart';
3 | import 'package:flutter/material.dart';
4 | import 'package:yalo_locale/lib.dart';
5 |
6 | void main() {
7 | runApp(
8 | DevicePreview(
9 | enabled: kReleaseMode == false,
10 | availableLocales: supportedLocales,
11 | tools: const [
12 | DeviceSection(
13 | orientation: false,
14 | frameVisibility: false,
15 | ),
16 | SystemSection(
17 | theme: false,
18 | ),
19 | ],
20 | builder: (BuildContext context) => const PresidentsApp(),
21 | ),
22 | );
23 | }
24 |
25 | class PresidentsApp extends StatelessWidget {
26 | const PresidentsApp({super.key});
27 |
28 | @override
29 | Widget build(BuildContext context) {
30 | return MaterialApp(
31 | localizationsDelegates: localizationsDelegates,
32 | supportedLocales: supportedLocales,
33 | locale: DevicePreview.locale(context),
34 | onGenerateTitle: (BuildContext context) => Messages.of(context).app.title,
35 | theme: ThemeData(
36 | primarySwatch: Colors.blue,
37 | ),
38 | useInheritedMediaQuery: true,
39 | builder: DevicePreview.appBuilder,
40 | home: const MyHomePage(),
41 | );
42 | }
43 | }
44 |
45 | class MyHomePage extends StatefulWidget {
46 | const MyHomePage({Key? key}) : super(key: key);
47 |
48 | @override
49 | MyHomePageState createState() => MyHomePageState();
50 | }
51 |
52 | class MyHomePageState extends State {
53 | int _counter = 1;
54 |
55 | void _incrementCounter() {
56 | setState(() {
57 | _counter++;
58 | if (_counter > 46) {
59 | _counter = 1;
60 | }
61 | });
62 | }
63 |
64 | @override
65 | Widget build(BuildContext context) {
66 | final LocalizationMessages loc = Messages.of(context);
67 | final String title = loc
68 | .getContent('mainView')
69 | .getContent('firstTab')
70 | .getContent('secondStory')
71 | .getContent('example')
72 | .getContent('title');
73 |
74 | return Scaffold(
75 | appBar: AppBar(
76 | title: Text(loc.app.description),
77 | ),
78 | body: Center(
79 | child: Column(
80 | mainAxisAlignment: MainAxisAlignment.center,
81 | children: [
82 | Padding(
83 | padding: const EdgeInsets.only(bottom: 20),
84 | child: Text(
85 | loc.books(user: loc.presidents.getContent('p$_counter'), howMany: _counter),
86 | textAlign: TextAlign.center,
87 | ),
88 | ),
89 | ],
90 | ),
91 | ),
92 | floatingActionButton: FloatingActionButton(
93 | onPressed: _incrementCounter,
94 | tooltip: loc.tooltips.increment,
95 | child: const Icon(Icons.add),
96 | ),
97 | );
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/example/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.10)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 |
12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
13 | # which isn't available in 3.10.
14 | function(list_prepend LIST_NAME PREFIX)
15 | set(NEW_LIST "")
16 | foreach(element ${${LIST_NAME}})
17 | list(APPEND NEW_LIST "${PREFIX}${element}")
18 | endforeach(element)
19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
20 | endfunction()
21 |
22 | # === Flutter Library ===
23 | # System-level dependencies.
24 | find_package(PkgConfig REQUIRED)
25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
28 |
29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
30 |
31 | # Published to parent scope for install step.
32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
36 |
37 | list(APPEND FLUTTER_LIBRARY_HEADERS
38 | "fl_basic_message_channel.h"
39 | "fl_binary_codec.h"
40 | "fl_binary_messenger.h"
41 | "fl_dart_project.h"
42 | "fl_engine.h"
43 | "fl_json_message_codec.h"
44 | "fl_json_method_codec.h"
45 | "fl_message_codec.h"
46 | "fl_method_call.h"
47 | "fl_method_channel.h"
48 | "fl_method_codec.h"
49 | "fl_method_response.h"
50 | "fl_plugin_registrar.h"
51 | "fl_plugin_registry.h"
52 | "fl_standard_message_codec.h"
53 | "fl_standard_method_codec.h"
54 | "fl_string_codec.h"
55 | "fl_value.h"
56 | "fl_view.h"
57 | "flutter_linux.h"
58 | )
59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
60 | add_library(flutter INTERFACE)
61 | target_include_directories(flutter INTERFACE
62 | "${EPHEMERAL_DIR}"
63 | )
64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
65 | target_link_libraries(flutter INTERFACE
66 | PkgConfig::GTK
67 | PkgConfig::GLIB
68 | PkgConfig::GIO
69 | )
70 | add_dependencies(flutter flutter_assemble)
71 |
72 | # === Flutter tool backend ===
73 | # _phony_ is a non-existent file to force this command to run every time,
74 | # since currently there's no way to get a full input/output list from the
75 | # flutter tool.
76 | add_custom_command(
77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
79 | COMMAND ${CMAKE_COMMAND} -E env
80 | ${FLUTTER_TOOL_ENVIRONMENT}
81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
83 | VERBATIM
84 | )
85 | add_custom_target(flutter_assemble DEPENDS
86 | "${FLUTTER_LIBRARY}"
87 | ${FLUTTER_LIBRARY_HEADERS}
88 | )
89 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/example/windows/runner/Runner.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #pragma code_page(65001)
4 | #include "resource.h"
5 |
6 | #define APSTUDIO_READONLY_SYMBOLS
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // Generated from the TEXTINCLUDE 2 resource.
10 | //
11 | #include "winres.h"
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | #undef APSTUDIO_READONLY_SYMBOLS
15 |
16 | /////////////////////////////////////////////////////////////////////////////
17 | // English (United States) resources
18 |
19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_APP_ICON ICON "resources\\app_icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | #ifdef FLUTTER_BUILD_NUMBER
64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
65 | #else
66 | #define VERSION_AS_NUMBER 1,0,0
67 | #endif
68 |
69 | #ifdef FLUTTER_BUILD_NAME
70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME
71 | #else
72 | #define VERSION_AS_STRING "1.0.0"
73 | #endif
74 |
75 | VS_VERSION_INFO VERSIONINFO
76 | FILEVERSION VERSION_AS_NUMBER
77 | PRODUCTVERSION VERSION_AS_NUMBER
78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79 | #ifdef _DEBUG
80 | FILEFLAGS VS_FF_DEBUG
81 | #else
82 | FILEFLAGS 0x0L
83 | #endif
84 | FILEOS VOS__WINDOWS32
85 | FILETYPE VFT_APP
86 | FILESUBTYPE 0x0L
87 | BEGIN
88 | BLOCK "StringFileInfo"
89 | BEGIN
90 | BLOCK "040904e4"
91 | BEGIN
92 | VALUE "CompanyName", "com.alphamikle.yalo.example" "\0"
93 | VALUE "FileDescription", "example" "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "example" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.alphamikle.yalo.example. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "example.exe" "\0"
98 | VALUE "ProductName", "example" "\0"
99 | VALUE "ProductVersion", VERSION_AS_STRING "\0"
100 | END
101 | END
102 | BLOCK "VarFileInfo"
103 | BEGIN
104 | VALUE "Translation", 0x409, 1252
105 | END
106 | END
107 |
108 | #endif // English (United States) resources
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 |
112 |
113 | #ifndef APSTUDIO_INVOKED
114 | /////////////////////////////////////////////////////////////////////////////
115 | //
116 | // Generated from the TEXTINCLUDE 3 resource.
117 | //
118 |
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 | #endif // not APSTUDIO_INVOKED
122 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/lib/src/templates/localization_content_template.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/constants/constants.dart';
2 | import 'package:yalo/src/templates/namespace_template.dart';
3 | import 'package:yalo/src/templates/parsing_methods.dart';
4 | import 'package:yaml/yaml.dart';
5 |
6 | abstract class LocalizationContentTemplate {
7 | LocalizationContentTemplate({
8 | required this.title,
9 | required this.lang,
10 | required this.isFirst,
11 | });
12 |
13 | final String title;
14 |
15 | final String lang;
16 |
17 | final bool isFirst;
18 |
19 | final Set interfaces = {};
20 |
21 | String get interfaceStart;
22 |
23 | String get start;
24 |
25 | String get end => '''
26 | }
27 | ''';
28 |
29 | String messages = '';
30 |
31 | String interface = '';
32 |
33 | String namespaces = '';
34 |
35 | String contentMap = '';
36 |
37 | String get contentMapEnd => '''
38 | };
39 |
40 | ''';
41 |
42 | String get contentMapGetter => '''
43 | @override
44 | T getContent(String key) {
45 | final Object? content = _contentMap[key];
46 | if (content is T) {
47 | return content;
48 | }
49 | throw Exception('Not found correct content of type "\$T" by key "\$key"');
50 | }
51 | ''';
52 |
53 | void addSimpleMessage(String code, String value, [String desc = '']) {
54 | messages += getSimpleValue(code, value, desc);
55 | contentMap += _getContentMapValue(code);
56 | interface += getValueInterface(code, value);
57 | }
58 |
59 | void addComplexMessage(String code, YamlMap value) {
60 | if (value[kValue] != null) {
61 | addSimpleMessage(code, value[kValue], value[kDesc] ?? '');
62 | } else if (value[kZero] != null) {
63 | _addPluralMessage(
64 | code,
65 | zero: value[kZero],
66 | one: value[kOne],
67 | two: value[kTwo],
68 | few: value[kFew],
69 | many: value[kMany],
70 | other: value[kOther],
71 | desc: value[kDesc] ?? '',
72 | );
73 | } else {
74 | _addNamespaceMessage(code, lang, value);
75 | }
76 | }
77 |
78 | void _addPluralMessage(
79 | String code, {
80 | String? zero,
81 | String? one,
82 | String? two,
83 | String? few,
84 | String? many,
85 | String? other,
86 | String desc = '',
87 | }) {
88 | messages += getPluralValue(code, zero: zero, one: one, two: two, few: few, many: many, other: other, desc: desc);
89 | contentMap += _getContentMapValue(code);
90 | interface += getValueInterface(
91 | code,
92 | [
93 | zero ?? '',
94 | one ?? '',
95 | two ?? '',
96 | few ?? '',
97 | many ?? '',
98 | other ?? '',
99 | ].join(', '),
100 | isPlural: true,
101 | );
102 | }
103 |
104 | void _addNamespaceMessage(String code, String lang, YamlMap value) {
105 | final NamespaceTemplate namespaceTemplate = NamespaceTemplate(
106 | title: code,
107 | contents: value,
108 | lang: lang,
109 | isFirst: isFirst,
110 | parent: title.toLowerCase() == lang.toLowerCase() ? '' : title,
111 | );
112 | namespaces += namespaceTemplate.toString();
113 | interfaces.addAll(namespaceTemplate.interfaces);
114 | interface += getNamespaceInterface(code, lang, title);
115 | messages += getNamespaceValue(code, lang, lang.toLowerCase() == title.toLowerCase() ? '' : title);
116 | contentMap += _getContentMapValue(code);
117 | }
118 |
119 | String _getContentMapValue(String code) {
120 | return '''
121 | '$code': $code,
122 | ''';
123 | }
124 |
125 | @override
126 | String toString() => throw UnimplementedError();
127 | }
128 |
--------------------------------------------------------------------------------
/assets/en_intl.yaml:
--------------------------------------------------------------------------------
1 | # The simplest possible message type [SimpleMessage]
2 | cancel: Cancel
3 |
4 | # Simple message type with description [SimpleMessage]
5 | save:
6 | value: Save
7 | desc: Saving something
8 |
9 | # Plural message [PluralMessage]
10 | book:
11 | zero: books
12 | one: book
13 | two: books
14 | other: books
15 | desc: Uses for description of books count
16 |
17 | # Namespace of group of messages [MessagesNamespace]
18 | namespacedZone:
19 | # [SimpleMessage]
20 | title: Title of Namespaced zone
21 | # [SimpleMessage]
22 | description: Description of Namespaced zone
23 | # [MessagesNamespace]
24 | checkout:
25 | # [SimpleMessage]
26 | title: Checkout for additional page
27 | # [MessagesNamespace]
28 | innerNamespacedZone:
29 | # [SimpleMessage]
30 | title: Deeper title of Inner namespaced zone with name ${name}
31 | # [SimpleMessage]
32 | description: Deeper description of Inner namespaced zone
33 | # [PluralMessage]
34 | book:
35 | # Required parameter of plural message
36 | zero: books
37 | # Required parameter of plural message
38 | one: book
39 | # Optional parameter of plural message
40 | two: books
41 | # Optional parameter of plural message
42 | few: books
43 | # Optional parameter of plural message
44 | many: books
45 | # Required parameter of plural message
46 | other: books
47 | # Optional parameter of plural message
48 | desc: Uses for description of books count
49 |
50 | # [MessagesNamespace]
51 | app:
52 | # [SimpleMessage]
53 | title: Yalo app
54 | # [SimpleMessage]
55 | description: This app will show you how to use yalo package
56 |
57 | # [MessagesNamespace]
58 | cart:
59 | # [SimpleMessage]
60 | title: Cart
61 | # [SimpleMessage]
62 | description: Please, fill the cart to do checkout
63 | # [MessagesNamespace]
64 | checkout:
65 | # [SimpleMessage]
66 | title: Checkout
67 | # [SimpleMessage]
68 | description: You should checkout
69 |
70 | # [PluralMessage]
71 | people:
72 | zero: I saw no people there
73 | one: I saw only one man there
74 | two: I saw two people there
75 | # Message with substitution of quantity of something
76 | few: I saw ${howMany} people there
77 | many: I saw ${howMany} or more people there
78 | other: I think, I saw ${howMany} people there
79 | desc: An example with numeric substitution in plural strings
80 |
81 | # [SimpleMessage] with additional substitution params
82 | greetings: Hello ${userName}! We are glad to see you at our ${hotelName} hotel!
83 |
84 | # [SimpleMessage] with description and substitution params
85 | weather:
86 | value: It's ${temperature} degrees outside today!
87 | desc: "Title on the main weather screen (see here: https://www.figma.com/community/file/974352831498882628)"
88 |
89 | # [PluralMessage] with additional substitution params and quantity substitution param
90 | shop:
91 | zero: There are no any ${shopName} shops
92 | one: There are exactly one ${shopName} shop
93 | two: There are two ${shopName} shops
94 | few: There are ${howMany} ${shopName} shops and we have plans to open additional at the ${city}!
95 | many: There are ${howMany} shops. Sorry, I didn't remember that shop name.
96 | other: Well, I tired to count these shops. I can say that there are only ${howMany} shops!
97 |
98 | # [PluralMessage] with additional substitution params and quantity substitution param
99 | mainScreen:
100 | product:
101 | zero: There no products.
102 | one: There is only one product left from the brand ${brand}.
103 | two: It is your last chance to buy product from the ${brand}.
104 | other: You can buy ${howMany} products
--------------------------------------------------------------------------------
/example/windows/runner/win32_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_WIN32_WINDOW_H_
2 | #define RUNNER_WIN32_WINDOW_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be
11 | // inherited from by classes that wish to specialize with custom
12 | // rendering and input handling
13 | class Win32Window {
14 | public:
15 | struct Point {
16 | unsigned int x;
17 | unsigned int y;
18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {}
19 | };
20 |
21 | struct Size {
22 | unsigned int width;
23 | unsigned int height;
24 | Size(unsigned int width, unsigned int height)
25 | : width(width), height(height) {}
26 | };
27 |
28 | Win32Window();
29 | virtual ~Win32Window();
30 |
31 | // Creates and shows a win32 window with |title| and position and size using
32 | // |origin| and |size|. New windows are created on the default monitor. Window
33 | // sizes are specified to the OS in physical pixels, hence to ensure a
34 | // consistent size to will treat the width height passed in to this function
35 | // as logical pixels and scale to appropriate for the default monitor. Returns
36 | // true if the window was created successfully.
37 | bool CreateAndShow(const std::wstring& title,
38 | const Point& origin,
39 | const Size& size);
40 |
41 | // Release OS resources associated with window.
42 | void Destroy();
43 |
44 | // Inserts |content| into the window tree.
45 | void SetChildContent(HWND content);
46 |
47 | // Returns the backing Window handle to enable clients to set icon and other
48 | // window properties. Returns nullptr if the window has been destroyed.
49 | HWND GetHandle();
50 |
51 | // If true, closing this window will quit the application.
52 | void SetQuitOnClose(bool quit_on_close);
53 |
54 | // Return a RECT representing the bounds of the current client area.
55 | RECT GetClientArea();
56 |
57 | protected:
58 | // Processes and route salient window messages for mouse handling,
59 | // size change and DPI. Delegates handling of these to member overloads that
60 | // inheriting classes can handle.
61 | virtual LRESULT MessageHandler(HWND window,
62 | UINT const message,
63 | WPARAM const wparam,
64 | LPARAM const lparam) noexcept;
65 |
66 | // Called when CreateAndShow is called, allowing subclass window-related
67 | // setup. Subclasses should return false if setup fails.
68 | virtual bool OnCreate();
69 |
70 | // Called when Destroy is called.
71 | virtual void OnDestroy();
72 |
73 | private:
74 | friend class WindowClassRegistrar;
75 |
76 | // OS callback called by message pump. Handles the WM_NCCREATE message which
77 | // is passed when the non-client area is being created and enables automatic
78 | // non-client DPI scaling so that the non-client area automatically
79 | // responsponds to changes in DPI. All other messages are handled by
80 | // MessageHandler.
81 | static LRESULT CALLBACK WndProc(HWND const window,
82 | UINT const message,
83 | WPARAM const wparam,
84 | LPARAM const lparam) noexcept;
85 |
86 | // Retrieves a class instance pointer for |window|
87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept;
88 |
89 | bool quit_on_close_ = false;
90 |
91 | // window handle for top level window.
92 | HWND window_handle_ = nullptr;
93 |
94 | // window handle for hosted content.
95 | HWND child_content_ = nullptr;
96 | };
97 |
98 | #endif // RUNNER_WIN32_WINDOW_H_
99 |
--------------------------------------------------------------------------------
/example/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.14)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
12 |
13 | # === Flutter Library ===
14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
15 |
16 | # Published to parent scope for install step.
17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
21 |
22 | list(APPEND FLUTTER_LIBRARY_HEADERS
23 | "flutter_export.h"
24 | "flutter_windows.h"
25 | "flutter_messenger.h"
26 | "flutter_plugin_registrar.h"
27 | "flutter_texture_registrar.h"
28 | )
29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
30 | add_library(flutter INTERFACE)
31 | target_include_directories(flutter INTERFACE
32 | "${EPHEMERAL_DIR}"
33 | )
34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
35 | add_dependencies(flutter flutter_assemble)
36 |
37 | # === Wrapper ===
38 | list(APPEND CPP_WRAPPER_SOURCES_CORE
39 | "core_implementations.cc"
40 | "standard_codec.cc"
41 | )
42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
44 | "plugin_registrar.cc"
45 | )
46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
47 | list(APPEND CPP_WRAPPER_SOURCES_APP
48 | "flutter_engine.cc"
49 | "flutter_view_controller.cc"
50 | )
51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
52 |
53 | # Wrapper sources needed for a plugin.
54 | add_library(flutter_wrapper_plugin STATIC
55 | ${CPP_WRAPPER_SOURCES_CORE}
56 | ${CPP_WRAPPER_SOURCES_PLUGIN}
57 | )
58 | apply_standard_settings(flutter_wrapper_plugin)
59 | set_target_properties(flutter_wrapper_plugin PROPERTIES
60 | POSITION_INDEPENDENT_CODE ON)
61 | set_target_properties(flutter_wrapper_plugin PROPERTIES
62 | CXX_VISIBILITY_PRESET hidden)
63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
64 | target_include_directories(flutter_wrapper_plugin PUBLIC
65 | "${WRAPPER_ROOT}/include"
66 | )
67 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
68 |
69 | # Wrapper sources needed for the runner.
70 | add_library(flutter_wrapper_app STATIC
71 | ${CPP_WRAPPER_SOURCES_CORE}
72 | ${CPP_WRAPPER_SOURCES_APP}
73 | )
74 | apply_standard_settings(flutter_wrapper_app)
75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
76 | target_include_directories(flutter_wrapper_app PUBLIC
77 | "${WRAPPER_ROOT}/include"
78 | )
79 | add_dependencies(flutter_wrapper_app flutter_assemble)
80 |
81 | # === Flutter tool backend ===
82 | # _phony_ is a non-existent file to force this command to run every time,
83 | # since currently there's no way to get a full input/output list from the
84 | # flutter tool.
85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
87 | add_custom_command(
88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
90 | ${CPP_WRAPPER_SOURCES_APP}
91 | ${PHONY_OUTPUT}
92 | COMMAND ${CMAKE_COMMAND} -E env
93 | ${FLUTTER_TOOL_ENVIRONMENT}
94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
95 | windows-x64 $
96 | VERBATIM
97 | )
98 | add_custom_target(flutter_assemble DEPENDS
99 | "${FLUTTER_LIBRARY}"
100 | ${FLUTTER_LIBRARY_HEADERS}
101 | ${CPP_WRAPPER_SOURCES_CORE}
102 | ${CPP_WRAPPER_SOURCES_PLUGIN}
103 | ${CPP_WRAPPER_SOURCES_APP}
104 | )
105 |
--------------------------------------------------------------------------------
/example/linux/my_application.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | #include
4 | #ifdef GDK_WINDOWING_X11
5 | #include
6 | #endif
7 |
8 | #include "flutter/generated_plugin_registrant.h"
9 |
10 | struct _MyApplication {
11 | GtkApplication parent_instance;
12 | char** dart_entrypoint_arguments;
13 | };
14 |
15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16 |
17 | // Implements GApplication::activate.
18 | static void my_application_activate(GApplication* application) {
19 | MyApplication* self = MY_APPLICATION(application);
20 | GtkWindow* window =
21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22 |
23 | // Use a header bar when running in GNOME as this is the common style used
24 | // by applications and is the setup most users will be using (e.g. Ubuntu
25 | // desktop).
26 | // If running on X and not using GNOME then just use a traditional title bar
27 | // in case the window manager does more exotic layout, e.g. tiling.
28 | // If running on Wayland assume the header bar will work (may need changing
29 | // if future cases occur).
30 | gboolean use_header_bar = TRUE;
31 | #ifdef GDK_WINDOWING_X11
32 | GdkScreen* screen = gtk_window_get_screen(window);
33 | if (GDK_IS_X11_SCREEN(screen)) {
34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36 | use_header_bar = FALSE;
37 | }
38 | }
39 | #endif
40 | if (use_header_bar) {
41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42 | gtk_widget_show(GTK_WIDGET(header_bar));
43 | gtk_header_bar_set_title(header_bar, "example");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | } else {
47 | gtk_window_set_title(window, "example");
48 | }
49 |
50 | gtk_window_set_default_size(window, 1280, 720);
51 | gtk_widget_show(GTK_WIDGET(window));
52 |
53 | g_autoptr(FlDartProject) project = fl_dart_project_new();
54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
55 |
56 | FlView* view = fl_view_new(project);
57 | gtk_widget_show(GTK_WIDGET(view));
58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
59 |
60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
61 |
62 | gtk_widget_grab_focus(GTK_WIDGET(view));
63 | }
64 |
65 | // Implements GApplication::local_command_line.
66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
67 | MyApplication* self = MY_APPLICATION(application);
68 | // Strip out the first argument as it is the binary name.
69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
70 |
71 | g_autoptr(GError) error = nullptr;
72 | if (!g_application_register(application, nullptr, &error)) {
73 | g_warning("Failed to register: %s", error->message);
74 | *exit_status = 1;
75 | return TRUE;
76 | }
77 |
78 | g_application_activate(application);
79 | *exit_status = 0;
80 |
81 | return TRUE;
82 | }
83 |
84 | // Implements GObject::dispose.
85 | static void my_application_dispose(GObject* object) {
86 | MyApplication* self = MY_APPLICATION(object);
87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
89 | }
90 |
91 | static void my_application_class_init(MyApplicationClass* klass) {
92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
95 | }
96 |
97 | static void my_application_init(MyApplication* self) {}
98 |
99 | MyApplication* my_application_new() {
100 | return MY_APPLICATION(g_object_new(my_application_get_type(),
101 | "application-id", APPLICATION_ID,
102 | "flags", G_APPLICATION_NON_UNIQUE,
103 | nullptr));
104 | }
105 |
--------------------------------------------------------------------------------
/example/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.14)
3 | project(example LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "example")
8 |
9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10 | # versions of CMake.
11 | cmake_policy(SET CMP0063 NEW)
12 |
13 | # Define build configuration option.
14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
15 | if(IS_MULTICONFIG)
16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
17 | CACHE STRING "" FORCE)
18 | else()
19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
20 | set(CMAKE_BUILD_TYPE "Debug" CACHE
21 | STRING "Flutter build mode" FORCE)
22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
23 | "Debug" "Profile" "Release")
24 | endif()
25 | endif()
26 | # Define settings for the Profile build mode.
27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
31 |
32 | # Use Unicode for all projects.
33 | add_definitions(-DUNICODE -D_UNICODE)
34 |
35 | # Compilation settings that should be applied to most targets.
36 | #
37 | # Be cautious about adding new options here, as plugins use this function by
38 | # default. In most cases, you should add new options to specific targets instead
39 | # of modifying this function.
40 | function(APPLY_STANDARD_SETTINGS TARGET)
41 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
43 | target_compile_options(${TARGET} PRIVATE /EHsc)
44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
46 | endfunction()
47 |
48 | # Flutter library and tool build rules.
49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
50 | add_subdirectory(${FLUTTER_MANAGED_DIR})
51 |
52 | # Application build; see runner/CMakeLists.txt.
53 | add_subdirectory("runner")
54 |
55 | # Generated plugin build rules, which manage building the plugins and adding
56 | # them to the application.
57 | include(flutter/generated_plugins.cmake)
58 |
59 |
60 | # === Installation ===
61 | # Support files are copied into place next to the executable, so that it can
62 | # run in place. This is done instead of making a separate bundle (as on Linux)
63 | # so that building and running from within Visual Studio will work.
64 | set(BUILD_BUNDLE_DIR "$")
65 | # Make the "install" step default, as it's required to run.
66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
69 | endif()
70 |
71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
73 |
74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
75 | COMPONENT Runtime)
76 |
77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
78 | COMPONENT Runtime)
79 |
80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
81 | COMPONENT Runtime)
82 |
83 | if(PLUGIN_BUNDLED_LIBRARIES)
84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
86 | COMPONENT Runtime)
87 | endif()
88 |
89 | # Fully re-copy the assets directory on each build to avoid having stale files
90 | # from a previous install.
91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
92 | install(CODE "
93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
94 | " COMPONENT Runtime)
95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
97 |
98 | # Install the AOT library on non-Debug builds only.
99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
100 | CONFIGURATIONS Profile;Release
101 | COMPONENT Runtime)
102 |
--------------------------------------------------------------------------------
/example/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.10)
3 | project(runner LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "example")
8 | # The unique GTK application identifier for this application. See:
9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID
10 | set(APPLICATION_ID "com.alphamikle.yalo.example.example")
11 |
12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
13 | # versions of CMake.
14 | cmake_policy(SET CMP0063 NEW)
15 |
16 | # Load bundled libraries from the lib/ directory relative to the binary.
17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
18 |
19 | # Root filesystem for cross-building.
20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27 | endif()
28 |
29 | # Define build configuration options.
30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
31 | set(CMAKE_BUILD_TYPE "Debug" CACHE
32 | STRING "Flutter build mode" FORCE)
33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34 | "Debug" "Profile" "Release")
35 | endif()
36 |
37 | # Compilation settings that should be applied to most targets.
38 | #
39 | # Be cautious about adding new options here, as plugins use this function by
40 | # default. In most cases, you should add new options to specific targets instead
41 | # of modifying this function.
42 | function(APPLY_STANDARD_SETTINGS TARGET)
43 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
47 | endfunction()
48 |
49 | # Flutter library and tool build rules.
50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
51 | add_subdirectory(${FLUTTER_MANAGED_DIR})
52 |
53 | # System-level dependencies.
54 | find_package(PkgConfig REQUIRED)
55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
56 |
57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
58 |
59 | # Define the application target. To change its name, change BINARY_NAME above,
60 | # not the value here, or `flutter run` will no longer work.
61 | #
62 | # Any new source files that you add to the application should be added here.
63 | add_executable(${BINARY_NAME}
64 | "main.cc"
65 | "my_application.cc"
66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
67 | )
68 |
69 | # Apply the standard set of build settings. This can be removed for applications
70 | # that need different build settings.
71 | apply_standard_settings(${BINARY_NAME})
72 |
73 | # Add dependency libraries. Add any application-specific dependencies here.
74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
76 |
77 | # Run the Flutter tool portions of the build. This must not be removed.
78 | add_dependencies(${BINARY_NAME} flutter_assemble)
79 |
80 | # Only the install-generated bundle's copy of the executable will launch
81 | # correctly, since the resources must in the right relative locations. To avoid
82 | # people trying to run the unbundled copy, put it in a subdirectory instead of
83 | # the default top-level location.
84 | set_target_properties(${BINARY_NAME}
85 | PROPERTIES
86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
87 | )
88 |
89 | # Generated plugin build rules, which manage building the plugins and adding
90 | # them to the application.
91 | include(flutter/generated_plugins.cmake)
92 |
93 |
94 | # === Installation ===
95 | # By default, "installing" just makes a relocatable bundle in the build
96 | # directory.
97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
100 | endif()
101 |
102 | # Start with a clean build bundle directory every time.
103 | install(CODE "
104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
105 | " COMPONENT Runtime)
106 |
107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
109 |
110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
111 | COMPONENT Runtime)
112 |
113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
114 | COMPONENT Runtime)
115 |
116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
117 | COMPONENT Runtime)
118 |
119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
120 | install(FILES "${bundled_library}"
121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
122 | COMPONENT Runtime)
123 | endforeach(bundled_library)
124 |
125 | # Fully re-copy the assets directory on each build to avoid having stale files
126 | # from a previous install.
127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
128 | install(CODE "
129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
130 | " COMPONENT Runtime)
131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
133 |
134 | # Install the AOT library on non-Debug builds only.
135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
137 | COMPONENT Runtime)
138 | endif()
139 |
--------------------------------------------------------------------------------
/lib/src/templates/parsing_methods.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/constants/constants.dart';
2 | import 'package:yalo/src/templates/localization_content_template.dart';
3 | import 'package:yalo/src/utils/utils.dart';
4 | import 'package:yaml/yaml.dart';
5 |
6 | RegExp get _substitutionRegExp => RegExp(r'\$\{(\w+)\}');
7 |
8 | void _nullException(String? value, [String name = kCode]) {
9 | if (value == null) {
10 | throw ArgumentError.notNull(name);
11 | }
12 | }
13 |
14 | void _emptyException(String value, [String name = kCode]) {
15 | if (value.isEmpty) {
16 | throw ArgumentError.value(value, name, '$name must not been empty');
17 | }
18 | }
19 |
20 | bool _hasSubstitution(String value) {
21 | final List matches = _substitutionRegExp.allMatches(value).toList();
22 | return matches.isNotEmpty && matches.any((RegExpMatch match) => match.group(1) != kHowMany);
23 | }
24 |
25 | String _generateArgumentsFromValue(String value, {bool isPlural = false}) {
26 | final Iterable matches = _substitutionRegExp.allMatches(value);
27 | final Set arguments = {};
28 |
29 | for (final RegExpMatch match in matches) {
30 | final String argumentName = match.group(0).toString().replaceAll(RegExp(r'^\$\{|\}$'), '');
31 | if (argumentName == kHowMany) {
32 | arguments.add('required int $argumentName');
33 | } else {
34 | arguments.add('required String $argumentName');
35 | }
36 | }
37 | return '{${arguments.join(', ')},${isPlural ? ' int? precision,' : ''}}';
38 | }
39 |
40 | String _removeExtraBraces(String code) {
41 | return code.replaceAllMapped(RegExp(r'\${(\w+)}'), (Match match) => '\$${match.group(1) ?? ''}');
42 | }
43 |
44 | String getValueInterface(String code, String value, {bool isPlural = false}) {
45 | if (_hasSubstitution(value)) {
46 | return '''
47 | String $code(${_generateArgumentsFromValue(value, isPlural: isPlural)});
48 | ''';
49 | }
50 | if (isPlural) {
51 | return '''
52 | String $code(int $kHowMany, {int? precision});
53 | ''';
54 | }
55 | return '''
56 | String get $code;
57 | ''';
58 | }
59 |
60 | String getSimpleValue(String code, String value, [String desc = '']) {
61 | _nullException(code, kCode);
62 | _emptyException(code, kCode);
63 | _nullException(value, kValue);
64 |
65 | if (_hasSubstitution(value)) {
66 | return _removeExtraBraces('''
67 | /// Description: "$desc"
68 | /// Example: "$value"
69 | @override
70 | String $code(${_generateArgumentsFromValue(value)}) => Intl.message(\'\'\'$value\'\'\', name: '$code', desc: '$desc',);
71 | ''');
72 | }
73 |
74 | return _removeExtraBraces('''
75 | /// Description: "$desc"
76 | /// Example: "$value"
77 | @override
78 | final String $code = Intl.message(\'\'\'$value\'\'\', name: '$code', desc: '$desc',);
79 | ''');
80 | }
81 |
82 | String getPluralValue(
83 | String code, {
84 | String? zero,
85 | String? one,
86 | String? two,
87 | String? few,
88 | String? many,
89 | String? other,
90 | String desc = '',
91 | }) {
92 | _nullException(code, kCode);
93 | _nullException(zero, kZero);
94 | _nullException(one, kOne);
95 | _nullException(other, kOther);
96 | _emptyException(code, kCode);
97 |
98 | if (_hasSubstitution(zero ?? '') ||
99 | _hasSubstitution(one ?? '') ||
100 | _hasSubstitution(two ?? '') ||
101 | _hasSubstitution(few ?? '') ||
102 | _hasSubstitution(many ?? '') ||
103 | _hasSubstitution(other ?? '')) {
104 | return _removeExtraBraces('''
105 | /// Description: "$desc"
106 | /// Example: "zero: $zero, one: $one, two: $two, few: $few, many: $many, other: $other"
107 | @override
108 | String $code(${_generateArgumentsFromValue([
109 | zero ?? '',
110 | one ?? '',
111 | two ?? '',
112 | few ?? '',
113 | many ?? '',
114 | other ?? '',
115 | ].join(', '), isPlural: true)}) => Intl.plural($kHowMany,
116 | name: \'\'\'$code\'\'\',
117 | zero: \'\'\'$zero\'\'\',
118 | one: \'\'\'$one\'\'\',
119 | two: \'\'\'${two ?? other}\'\'\',
120 | few: \'\'\'${few ?? other}\'\'\',
121 | many: \'\'\'${many ?? other}\'\'\',
122 | other: \'\'\'$other\'\'\',
123 | desc: \'\'\'$desc\'\'\',
124 | precision: precision,
125 | );
126 | ''');
127 | }
128 |
129 | return _removeExtraBraces('''
130 | /// Description: "$desc"
131 | /// Example: "zero: $zero, one: $one, two: $two, few: $few, many: $many, other: $other"
132 | @override
133 | String $code(int $kHowMany, {int? precision}) => Intl.plural($kHowMany,
134 | name: \'\'\'$code\'\'\',
135 | zero: \'\'\'$zero\'\'\',
136 | one: \'\'\'$one\'\'\',
137 | two: \'\'\'${two ?? other}\'\'\',
138 | few: \'\'\'${few ?? other}\'\'\',
139 | many: \'\'\'${many ?? other}\'\'\',
140 | other: \'\'\'$other\'\'\',
141 | desc: \'\'\'$desc\'\'\',
142 | precision: precision,
143 | );
144 | ''');
145 | }
146 |
147 | String getNamespaceInterface(String code, String lang, String parent) {
148 | final parentName = capitalize(parent);
149 | final fieldName = capitalize(code);
150 | final clearFieldName = (parentName + fieldName).replaceFirst(lang, '');
151 | return '''
152 | $clearFieldName get $code;
153 | ''';
154 | }
155 |
156 | String getNamespaceValue(String code, String lang, String parent) {
157 | final parentName = capitalize(parent);
158 | final fieldName = capitalize(code);
159 | return '''
160 | @override
161 | final $parentName$fieldName $code = $lang$parentName$fieldName();
162 | ''';
163 | }
164 |
165 | void addMessageToLocalizationContentTemplate(dynamic value, String code, LocalizationContentTemplate template) {
166 | if (value is String || value is num) {
167 | template.addSimpleMessage(code, value.toString());
168 | } else if (value is YamlMap) {
169 | template.addComplexMessage(code, value);
170 | } else {
171 | throw Exception('Invalid format of message. Value: $value, key: $code, type: ${value.runtimeType}');
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/lib/src/locale_generator.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:path/path.dart' as p;
4 | import 'package:yalo/src/constants/constants.dart';
5 | import 'package:yalo/src/directory_reader.dart';
6 | import 'package:yalo/src/templates/intl_template.dart';
7 | import 'package:yalo/src/templates/language_template.dart';
8 | import 'package:yalo/src/templates/parsing_methods.dart';
9 | import 'package:yalo/src/utils/assets_scanner.dart';
10 | import 'package:yalo/src/utils/utils.dart';
11 | import 'package:yaml/yaml.dart';
12 |
13 | class LocaleGenerator with DirectoryReader {
14 | LocaleGenerator(List pathsToIntlFiles) : _customIntlFiles = Set.from(pathsToIntlFiles);
15 |
16 | final Set _customIntlFiles;
17 | final Set _intlFilesPaths = {};
18 | final Set _assetsFiles = {};
19 | late AssetsScanner scanner;
20 |
21 | late IntlTemplate _intlTemplate;
22 | final Map _languages = {};
23 | late String _intlFilesPrefix;
24 |
25 | List get languagesCodes => _languages.keys.toList();
26 | final Set _interfaces = {};
27 |
28 | String get localizationCode => _intlTemplate.template;
29 |
30 | String get _libraryCode => '''
31 | library yalo_locale;
32 |
33 | export 'src/locale.dart' show Messages, $kInterfaceName, localizationsDelegates, supportedLocales''';
34 |
35 | String generateLibrary() {
36 | return '$_libraryCode${_interfaces.isEmpty ? '' : ', '}${_interfaces.join(', ')};';
37 | }
38 |
39 | void generate() {
40 | scanner = AssetsScanner();
41 | scanAssets(scanner);
42 | _intlTemplate = IntlTemplate('LocalizationDelegate');
43 | _intlFilesPrefix = 'intl';
44 | _searchIntlFiles();
45 | _readIntlFiles();
46 | }
47 |
48 | bool _isIntlFile(String fileName) => fileName.contains(RegExp('$_intlFilesPrefix.ya?ml\$'));
49 |
50 | void _searchIntlFiles() {
51 | _intlFilesPaths.clear();
52 | _assetsFiles.clear();
53 | _assetsFiles.addAll(getAssetDirectoryFiles());
54 | for (String assetFile in _assetsFiles) {
55 | if (_isIntlFile(assetFile)) {
56 | _intlFilesPaths.add(assetFile);
57 | }
58 | }
59 | _intlFilesPaths.addAll(_customIntlFiles);
60 | }
61 |
62 | String _getLanguageCode(String originalFileName) {
63 | final RegExp regExp = RegExp('/([a-z]+)/?.?($_intlFilesPrefix).ya?ml\$');
64 | final RegExpMatch? match = regExp.firstMatch(originalFileName);
65 | if (match == null) {
66 | return 'en';
67 | }
68 | return match.group(1)!;
69 | }
70 |
71 | void _readIntlFiles() {
72 | _languages.clear();
73 | bool isFirst = true;
74 | final Map fileContents = {};
75 | for (final String intlFilePath in _intlFilesPaths) {
76 | final File file = File(p.join(path, intlFilePath));
77 | final String fileData = file.readAsStringSync();
78 | if (fileData.trim().isEmpty) {
79 | log(
80 | 'File "${file.path}" does not contain any localization data and will be skipped',
81 | name: kLocalizationGeneratorLogPrefix,
82 | );
83 | continue;
84 | }
85 | final YamlMap fileContent = loadYaml(fileData);
86 | fileContents[intlFilePath] = fileContent;
87 | }
88 | for (final String intlFilePath in _intlFilesPaths) {
89 | final YamlMap fileContent = fileContents[intlFilePath]!;
90 | for (final MapEntry entry in fileContent.entries) {
91 | _replaceLinks(
92 | entry: entry,
93 | fileContentKey: intlFilePath,
94 | fileContents: fileContents,
95 | );
96 | }
97 | }
98 | for (String intlFilePath in _intlFilesPaths) {
99 | final YamlMap fileContent = fileContents[intlFilePath]!;
100 | final List> entries = fileContent.entries.toList();
101 | final String languageCode = _getLanguageCode(intlFilePath);
102 | final LanguageTemplate languageTemplate = LanguageTemplate(title: capitalize(languageCode), isFirst: isFirst);
103 | for (MapEntry entry in entries) {
104 | _writeMessage(entry, languageTemplate);
105 | }
106 | _interfaces.addAll(languageTemplate.interfaces);
107 | _languages[languageCode] = languageTemplate;
108 | _intlTemplate.addLanguage(languageCode, languageTemplate);
109 | isFirst = false;
110 | }
111 | }
112 |
113 | void _writeMessage(MapEntry entry, LanguageTemplate template) {
114 | final String code = entry.key as String;
115 | final dynamic value = entry.value;
116 | addMessageToLocalizationContentTemplate(value, code, template);
117 | }
118 |
119 | void _replaceLinks({
120 | required MapEntry entry,
121 | required String fileContentKey,
122 | required Map fileContents,
123 | }) {
124 | final dynamic key = entry.key;
125 | final dynamic value = entry.value;
126 | if (value is String) {
127 | final RegExpMatch? match = RegExp(r'^~(?\w+).(?\w+)$').firstMatch(value);
128 | if (match != null) {
129 | final String targetLanguage = match.namedGroup('language')!;
130 | final String targetKey = match.namedGroup('key')!;
131 | String? targetFilePath;
132 | YamlMap? targetFileContent;
133 | for (final MapEntry entry in fileContents.entries) {
134 | final RegExp languageRegExp = RegExp('$targetLanguage.?_?');
135 | if (languageRegExp.hasMatch(entry.key)) {
136 | targetFilePath = entry.key;
137 | targetFileContent = entry.value;
138 | }
139 | }
140 | if (targetFileContent == null) {
141 | throw Exception('Not found target intl file for language "$targetLanguage" with value "$key: $value"');
142 | }
143 | final Object? targetValue = targetFileContent[targetKey];
144 | if (targetValue == null) {
145 | throw Exception('Not found value with root key "$targetKey" in intl file "$targetFilePath"');
146 | }
147 | final Map mutableFileContent = Map.fromEntries(fileContents[fileContentKey]!.entries);
148 | mutableFileContent[targetKey] = targetValue;
149 | fileContents[fileContentKey] = YamlMap.wrap(mutableFileContent);
150 | }
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/lib/src/assets_generator.dart:
--------------------------------------------------------------------------------
1 | import 'package:yalo/src/directory_reader.dart';
2 | import 'package:yalo/src/utils/assets_scanner.dart';
3 |
4 | const kAssetsEnum = 'Asset';
5 | const kAssetsEnumMap = '_assetEnumMap';
6 |
7 | /// Generator for user classes, annotated with @AstHelp
8 | class AssetsGenerator with DirectoryReader {
9 | final Set _assetsFiles = {};
10 | final Set _assetsFields = {};
11 | late AssetsScanner scanner;
12 | final Set _preloadMimes = {
13 | 'txt',
14 | 'json',
15 | 'yaml',
16 | 'yml',
17 | // add more
18 | };
19 |
20 | String template = '';
21 |
22 | String get dependencies => '''
23 | import 'package:flutter/services.dart';
24 | ''';
25 |
26 | String get libExporter => '''
27 | library yalo_assets;
28 |
29 | export 'src/assets.dart';
30 | ''';
31 |
32 | /// Returns assets mixin start
33 | String _startClass(String title) {
34 | return 'class $title {\n';
35 | }
36 |
37 | String _replaceSlash(String assetField) {
38 | return assetField.replaceAll('/', '_').replaceAll(' ', '_');
39 | }
40 |
41 | String _replaceDash(String assetField) {
42 | return assetField.replaceAll('-', '_');
43 | }
44 |
45 | String _replaceExtension(String assetField) {
46 | return assetField.replaceAll(RegExp(r'\.[a-zA-Z\d]+$'), '');
47 | }
48 |
49 | String _replaceUnderscore(String assetField) {
50 | assetField = assetField
51 | .replaceAllMapped(RegExp(r'_([a-zA-Z\d])'), (Match match) => match.group(1)!.toUpperCase())
52 | .replaceAll('_', '');
53 | return assetField.replaceAllMapped(RegExp(r'^([A-Z])'), (Match match) => match.group(1)!.toLowerCase());
54 | }
55 |
56 | String _replaceDot(String assetField) {
57 | assetField = assetField
58 | .replaceAllMapped(RegExp(r'\.([a-zA-Z\d])'), (Match match) => match.group(1)!.toUpperCase())
59 | .replaceAll('.', '');
60 | return assetField.replaceAllMapped(RegExp(r'^([A-Z])'), (Match match) => match.group(1)!.toLowerCase());
61 | }
62 |
63 | /// Replace invalid dart variable names for correct with prefix asset...
64 | String _checkForInvalidFieldName(String assetField) {
65 | if (!assetField.contains(RegExp(r'^[a-z_$]'))) {
66 | assetField = 'asset$assetField';
67 | }
68 | return assetField;
69 | }
70 |
71 | /// Check for same file name in several files in different dirs
72 | String _checkForCopy(String assetField, String assetFileName) {
73 | if (_assetsFields.contains(assetField) && !_assetsFiles.contains(assetFileName)) {
74 | assetField += 'Copy';
75 | return _checkForCopy(assetField, assetFileName);
76 | }
77 | return assetField;
78 | }
79 |
80 | /// Add an asset mixin field with an asset full path and short name
81 | String _getClassField(String preparedField) {
82 | return 'String get $preparedField => ${preparedField}S;\n';
83 | }
84 |
85 | String _prepareClassField(String assetFileName) {
86 | String assetField = getOnlyAssetFileName(assetFileName);
87 | assetField = _replaceSlash(assetField);
88 | assetField = _replaceDash(assetField);
89 | assetField = _replaceExtension(assetField);
90 | assetField = _replaceUnderscore(assetField);
91 | assetField = _replaceDot(assetField);
92 | assetField = _checkForInvalidFieldName(assetField);
93 | assetField = _checkForCopy(assetField, assetFileName);
94 | _assetsFields.add(assetField);
95 | _assetsFiles.add(assetFileName);
96 | return assetField;
97 | }
98 |
99 | String _getAssetStaticField(String assetFileName, String preparedField) {
100 | return 'static const String ${preparedField}S = \'$assetFileName\';\n';
101 | }
102 |
103 | String _startEnum() {
104 | return '''enum $kAssetsEnum {
105 | _stub,
106 | ''';
107 | }
108 |
109 | String _closeEnum(String assetEnum) {
110 | return '$assetEnum\n}\n';
111 | }
112 |
113 | String _startEnumMap() {
114 | return '\nfinal Map<$kAssetsEnum, String> $kAssetsEnumMap = {\n';
115 | }
116 |
117 | String _addToEnumMap(String enumField, String assetFileName) {
118 | final String fieldName = RegExp(r'^([a-zA-Z\d]+)').firstMatch(enumField)!.group(1)!;
119 | return '$kAssetsEnum.$fieldName: \'$assetFileName\',\n';
120 | }
121 |
122 | String _closeEnumMap(String enumMap) {
123 | return '$enumMap\n};\n\n';
124 | }
125 |
126 | /// Generate preload assets function
127 | String _preloadAssets() {
128 | return '''
129 | final Map<$kAssetsEnum, String> _preloadedAssets = Map();
130 | bool isPreloaded = false;
131 | Future preloadAssets() async {
132 | final List loaders = [];
133 | loadAsset($kAssetsEnum asset) async {
134 | final String assetContent = await rootBundle.loadString($kAssetsEnumMap[asset]!, cache: false);
135 | _preloadedAssets[asset] = assetContent;
136 | }
137 | for ($kAssetsEnum assetEnumField in $kAssetsEnum.values) {
138 | loaders.add(loadAsset(assetEnumField));
139 | }
140 | await Future.wait(loaders);
141 | isPreloaded = true;
142 | return isPreloaded;
143 | }
144 | String getAssetData($kAssetsEnum assetEnum) {
145 | if (!isPreloaded) {
146 | throw Exception('You should run method "preloadAssets" before accessing data with "getAssetData" method');
147 | }
148 | return _preloadedAssets[assetEnum]!;
149 | }''';
150 | }
151 |
152 | String _endClass(String mixin) {
153 | return '$mixin\n}';
154 | }
155 |
156 | void generate() {
157 | scanner = AssetsScanner();
158 | scanAssets(scanner);
159 | template = _startClass('Assets');
160 | final Set tempAssetsFiles = getAssetDirectoryFiles();
161 | String assetEnum = _startEnum();
162 | String enumMap = _startEnumMap();
163 | for (String assetFile in tempAssetsFiles) {
164 | final String preparedField = _prepareClassField(assetFile);
165 | final String fieldName = _getClassField(preparedField);
166 | final String staticFieldName = _getAssetStaticField(assetFile, preparedField);
167 | if (_preloadMimes.any((String mime) => assetFile.contains(RegExp('.$mime\$')))) {
168 | assetEnum += '$preparedField,\n';
169 | enumMap += _addToEnumMap(preparedField, assetFile);
170 | }
171 | template += fieldName;
172 | template += staticFieldName;
173 | }
174 | enumMap = _closeEnumMap(enumMap);
175 | assetEnum = _closeEnum(assetEnum);
176 | template += _preloadAssets();
177 | if (_assetsFiles.isEmpty) {
178 | template += '// Not found any asset file in assets folder';
179 | }
180 | template = _endClass(template);
181 | template = dependencies + assetEnum + enumMap + template;
182 | _assetsFiles.clear();
183 | _assetsFields.clear();
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | _fe_analyzer_shared:
5 | dependency: transitive
6 | description:
7 | name: _fe_analyzer_shared
8 | url: "https://pub.dartlang.org"
9 | source: hosted
10 | version: "40.0.0"
11 | analyzer:
12 | dependency: "direct main"
13 | description:
14 | name: analyzer
15 | url: "https://pub.dartlang.org"
16 | source: hosted
17 | version: "4.1.0"
18 | args:
19 | dependency: transitive
20 | description:
21 | name: args
22 | url: "https://pub.dartlang.org"
23 | source: hosted
24 | version: "2.3.1"
25 | async:
26 | dependency: transitive
27 | description:
28 | name: async
29 | url: "https://pub.dartlang.org"
30 | source: hosted
31 | version: "2.8.2"
32 | boolean_selector:
33 | dependency: transitive
34 | description:
35 | name: boolean_selector
36 | url: "https://pub.dartlang.org"
37 | source: hosted
38 | version: "2.1.0"
39 | characters:
40 | dependency: transitive
41 | description:
42 | name: characters
43 | url: "https://pub.dartlang.org"
44 | source: hosted
45 | version: "1.2.0"
46 | charcode:
47 | dependency: transitive
48 | description:
49 | name: charcode
50 | url: "https://pub.dartlang.org"
51 | source: hosted
52 | version: "1.3.1"
53 | clock:
54 | dependency: transitive
55 | description:
56 | name: clock
57 | url: "https://pub.dartlang.org"
58 | source: hosted
59 | version: "1.1.0"
60 | collection:
61 | dependency: transitive
62 | description:
63 | name: collection
64 | url: "https://pub.dartlang.org"
65 | source: hosted
66 | version: "1.16.0"
67 | convert:
68 | dependency: transitive
69 | description:
70 | name: convert
71 | url: "https://pub.dartlang.org"
72 | source: hosted
73 | version: "3.0.2"
74 | crypto:
75 | dependency: transitive
76 | description:
77 | name: crypto
78 | url: "https://pub.dartlang.org"
79 | source: hosted
80 | version: "3.0.2"
81 | dart_style:
82 | dependency: "direct main"
83 | description:
84 | name: dart_style
85 | url: "https://pub.dartlang.org"
86 | source: hosted
87 | version: "2.2.3"
88 | fake_async:
89 | dependency: transitive
90 | description:
91 | name: fake_async
92 | url: "https://pub.dartlang.org"
93 | source: hosted
94 | version: "1.3.0"
95 | file:
96 | dependency: transitive
97 | description:
98 | name: file
99 | url: "https://pub.dartlang.org"
100 | source: hosted
101 | version: "6.1.2"
102 | flutter:
103 | dependency: "direct main"
104 | description: flutter
105 | source: sdk
106 | version: "0.0.0"
107 | flutter_lints:
108 | dependency: "direct dev"
109 | description:
110 | name: flutter_lints
111 | url: "https://pub.dartlang.org"
112 | source: hosted
113 | version: "2.0.1"
114 | flutter_test:
115 | dependency: "direct dev"
116 | description: flutter
117 | source: sdk
118 | version: "0.0.0"
119 | glob:
120 | dependency: transitive
121 | description:
122 | name: glob
123 | url: "https://pub.dartlang.org"
124 | source: hosted
125 | version: "2.1.0"
126 | intl:
127 | dependency: "direct main"
128 | description:
129 | name: intl
130 | url: "https://pub.dartlang.org"
131 | source: hosted
132 | version: "0.17.0"
133 | lints:
134 | dependency: transitive
135 | description:
136 | name: lints
137 | url: "https://pub.dartlang.org"
138 | source: hosted
139 | version: "2.0.0"
140 | matcher:
141 | dependency: transitive
142 | description:
143 | name: matcher
144 | url: "https://pub.dartlang.org"
145 | source: hosted
146 | version: "0.12.11"
147 | material_color_utilities:
148 | dependency: transitive
149 | description:
150 | name: material_color_utilities
151 | url: "https://pub.dartlang.org"
152 | source: hosted
153 | version: "0.1.4"
154 | meta:
155 | dependency: transitive
156 | description:
157 | name: meta
158 | url: "https://pub.dartlang.org"
159 | source: hosted
160 | version: "1.7.0"
161 | package_config:
162 | dependency: transitive
163 | description:
164 | name: package_config
165 | url: "https://pub.dartlang.org"
166 | source: hosted
167 | version: "2.1.0"
168 | path:
169 | dependency: "direct main"
170 | description:
171 | name: path
172 | url: "https://pub.dartlang.org"
173 | source: hosted
174 | version: "1.8.1"
175 | pub_semver:
176 | dependency: transitive
177 | description:
178 | name: pub_semver
179 | url: "https://pub.dartlang.org"
180 | source: hosted
181 | version: "2.1.1"
182 | sky_engine:
183 | dependency: transitive
184 | description: flutter
185 | source: sdk
186 | version: "0.0.99"
187 | source_span:
188 | dependency: transitive
189 | description:
190 | name: source_span
191 | url: "https://pub.dartlang.org"
192 | source: hosted
193 | version: "1.8.2"
194 | stack_trace:
195 | dependency: transitive
196 | description:
197 | name: stack_trace
198 | url: "https://pub.dartlang.org"
199 | source: hosted
200 | version: "1.10.0"
201 | stream_channel:
202 | dependency: transitive
203 | description:
204 | name: stream_channel
205 | url: "https://pub.dartlang.org"
206 | source: hosted
207 | version: "2.1.0"
208 | string_scanner:
209 | dependency: transitive
210 | description:
211 | name: string_scanner
212 | url: "https://pub.dartlang.org"
213 | source: hosted
214 | version: "1.1.0"
215 | term_glyph:
216 | dependency: transitive
217 | description:
218 | name: term_glyph
219 | url: "https://pub.dartlang.org"
220 | source: hosted
221 | version: "1.2.0"
222 | test_api:
223 | dependency: transitive
224 | description:
225 | name: test_api
226 | url: "https://pub.dartlang.org"
227 | source: hosted
228 | version: "0.4.9"
229 | typed_data:
230 | dependency: transitive
231 | description:
232 | name: typed_data
233 | url: "https://pub.dartlang.org"
234 | source: hosted
235 | version: "1.3.1"
236 | vector_math:
237 | dependency: transitive
238 | description:
239 | name: vector_math
240 | url: "https://pub.dartlang.org"
241 | source: hosted
242 | version: "2.1.2"
243 | watcher:
244 | dependency: transitive
245 | description:
246 | name: watcher
247 | url: "https://pub.dartlang.org"
248 | source: hosted
249 | version: "1.0.1"
250 | yaml:
251 | dependency: "direct main"
252 | description:
253 | name: yaml
254 | url: "https://pub.dartlang.org"
255 | source: hosted
256 | version: "3.1.1"
257 | sdks:
258 | dart: ">=2.17.0 <3.0.0"
259 | flutter: ">=3.0.0"
260 |
--------------------------------------------------------------------------------
/example/windows/runner/win32_window.cpp:
--------------------------------------------------------------------------------
1 | #include "win32_window.h"
2 |
3 | #include
4 |
5 | #include "resource.h"
6 |
7 | namespace {
8 |
9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
10 |
11 | // The number of Win32Window objects that currently exist.
12 | static int g_active_window_count = 0;
13 |
14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
15 |
16 | // Scale helper to convert logical scaler values to physical using passed in
17 | // scale factor
18 | int Scale(int source, double scale_factor) {
19 | return static_cast(source * scale_factor);
20 | }
21 |
22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
23 | // This API is only needed for PerMonitor V1 awareness mode.
24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) {
25 | HMODULE user32_module = LoadLibraryA("User32.dll");
26 | if (!user32_module) {
27 | return;
28 | }
29 | auto enable_non_client_dpi_scaling =
30 | reinterpret_cast(
31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
32 | if (enable_non_client_dpi_scaling != nullptr) {
33 | enable_non_client_dpi_scaling(hwnd);
34 | FreeLibrary(user32_module);
35 | }
36 | }
37 |
38 | } // namespace
39 |
40 | // Manages the Win32Window's window class registration.
41 | class WindowClassRegistrar {
42 | public:
43 | ~WindowClassRegistrar() = default;
44 |
45 | // Returns the singleton registar instance.
46 | static WindowClassRegistrar* GetInstance() {
47 | if (!instance_) {
48 | instance_ = new WindowClassRegistrar();
49 | }
50 | return instance_;
51 | }
52 |
53 | // Returns the name of the window class, registering the class if it hasn't
54 | // previously been registered.
55 | const wchar_t* GetWindowClass();
56 |
57 | // Unregisters the window class. Should only be called if there are no
58 | // instances of the window.
59 | void UnregisterWindowClass();
60 |
61 | private:
62 | WindowClassRegistrar() = default;
63 |
64 | static WindowClassRegistrar* instance_;
65 |
66 | bool class_registered_ = false;
67 | };
68 |
69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
70 |
71 | const wchar_t* WindowClassRegistrar::GetWindowClass() {
72 | if (!class_registered_) {
73 | WNDCLASS window_class{};
74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
75 | window_class.lpszClassName = kWindowClassName;
76 | window_class.style = CS_HREDRAW | CS_VREDRAW;
77 | window_class.cbClsExtra = 0;
78 | window_class.cbWndExtra = 0;
79 | window_class.hInstance = GetModuleHandle(nullptr);
80 | window_class.hIcon =
81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
82 | window_class.hbrBackground = 0;
83 | window_class.lpszMenuName = nullptr;
84 | window_class.lpfnWndProc = Win32Window::WndProc;
85 | RegisterClass(&window_class);
86 | class_registered_ = true;
87 | }
88 | return kWindowClassName;
89 | }
90 |
91 | void WindowClassRegistrar::UnregisterWindowClass() {
92 | UnregisterClass(kWindowClassName, nullptr);
93 | class_registered_ = false;
94 | }
95 |
96 | Win32Window::Win32Window() {
97 | ++g_active_window_count;
98 | }
99 |
100 | Win32Window::~Win32Window() {
101 | --g_active_window_count;
102 | Destroy();
103 | }
104 |
105 | bool Win32Window::CreateAndShow(const std::wstring& title,
106 | const Point& origin,
107 | const Size& size) {
108 | Destroy();
109 |
110 | const wchar_t* window_class =
111 | WindowClassRegistrar::GetInstance()->GetWindowClass();
112 |
113 | const POINT target_point = {static_cast(origin.x),
114 | static_cast(origin.y)};
115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
117 | double scale_factor = dpi / 96.0;
118 |
119 | HWND window = CreateWindow(
120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor),
123 | nullptr, nullptr, GetModuleHandle(nullptr), this);
124 |
125 | if (!window) {
126 | return false;
127 | }
128 |
129 | return OnCreate();
130 | }
131 |
132 | // static
133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window,
134 | UINT const message,
135 | WPARAM const wparam,
136 | LPARAM const lparam) noexcept {
137 | if (message == WM_NCCREATE) {
138 | auto window_struct = reinterpret_cast(lparam);
139 | SetWindowLongPtr(window, GWLP_USERDATA,
140 | reinterpret_cast(window_struct->lpCreateParams));
141 |
142 | auto that = static_cast(window_struct->lpCreateParams);
143 | EnableFullDpiSupportIfAvailable(window);
144 | that->window_handle_ = window;
145 | } else if (Win32Window* that = GetThisFromHandle(window)) {
146 | return that->MessageHandler(window, message, wparam, lparam);
147 | }
148 |
149 | return DefWindowProc(window, message, wparam, lparam);
150 | }
151 |
152 | LRESULT
153 | Win32Window::MessageHandler(HWND hwnd,
154 | UINT const message,
155 | WPARAM const wparam,
156 | LPARAM const lparam) noexcept {
157 | switch (message) {
158 | case WM_DESTROY:
159 | window_handle_ = nullptr;
160 | Destroy();
161 | if (quit_on_close_) {
162 | PostQuitMessage(0);
163 | }
164 | return 0;
165 |
166 | case WM_DPICHANGED: {
167 | auto newRectSize = reinterpret_cast(lparam);
168 | LONG newWidth = newRectSize->right - newRectSize->left;
169 | LONG newHeight = newRectSize->bottom - newRectSize->top;
170 |
171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
173 |
174 | return 0;
175 | }
176 | case WM_SIZE: {
177 | RECT rect = GetClientArea();
178 | if (child_content_ != nullptr) {
179 | // Size and position the child window.
180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
181 | rect.bottom - rect.top, TRUE);
182 | }
183 | return 0;
184 | }
185 |
186 | case WM_ACTIVATE:
187 | if (child_content_ != nullptr) {
188 | SetFocus(child_content_);
189 | }
190 | return 0;
191 | }
192 |
193 | return DefWindowProc(window_handle_, message, wparam, lparam);
194 | }
195 |
196 | void Win32Window::Destroy() {
197 | OnDestroy();
198 |
199 | if (window_handle_) {
200 | DestroyWindow(window_handle_);
201 | window_handle_ = nullptr;
202 | }
203 | if (g_active_window_count == 0) {
204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
205 | }
206 | }
207 |
208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
209 | return reinterpret_cast(
210 | GetWindowLongPtr(window, GWLP_USERDATA));
211 | }
212 |
213 | void Win32Window::SetChildContent(HWND content) {
214 | child_content_ = content;
215 | SetParent(content, window_handle_);
216 | RECT frame = GetClientArea();
217 |
218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
219 | frame.bottom - frame.top, true);
220 |
221 | SetFocus(child_content_);
222 | }
223 |
224 | RECT Win32Window::GetClientArea() {
225 | RECT frame;
226 | GetClientRect(window_handle_, &frame);
227 | return frame;
228 | }
229 |
230 | HWND Win32Window::GetHandle() {
231 | return window_handle_;
232 | }
233 |
234 | void Win32Window::SetQuitOnClose(bool quit_on_close) {
235 | quit_on_close_ = quit_on_close;
236 | }
237 |
238 | bool Win32Window::OnCreate() {
239 | // No-op; provided for subclasses.
240 | return true;
241 | }
242 |
243 | void Win32Window::OnDestroy() {
244 | // No-op; provided for subclasses.
245 | }
246 |
--------------------------------------------------------------------------------
/example/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | _fe_analyzer_shared:
5 | dependency: transitive
6 | description:
7 | name: _fe_analyzer_shared
8 | url: "https://pub.dartlang.org"
9 | source: hosted
10 | version: "40.0.0"
11 | analyzer:
12 | dependency: transitive
13 | description:
14 | name: analyzer
15 | url: "https://pub.dartlang.org"
16 | source: hosted
17 | version: "4.1.0"
18 | args:
19 | dependency: transitive
20 | description:
21 | name: args
22 | url: "https://pub.dartlang.org"
23 | source: hosted
24 | version: "2.3.1"
25 | async:
26 | dependency: transitive
27 | description:
28 | name: async
29 | url: "https://pub.dartlang.org"
30 | source: hosted
31 | version: "2.8.2"
32 | boolean_selector:
33 | dependency: transitive
34 | description:
35 | name: boolean_selector
36 | url: "https://pub.dartlang.org"
37 | source: hosted
38 | version: "2.1.0"
39 | characters:
40 | dependency: transitive
41 | description:
42 | name: characters
43 | url: "https://pub.dartlang.org"
44 | source: hosted
45 | version: "1.2.0"
46 | charcode:
47 | dependency: transitive
48 | description:
49 | name: charcode
50 | url: "https://pub.dartlang.org"
51 | source: hosted
52 | version: "1.3.1"
53 | clock:
54 | dependency: transitive
55 | description:
56 | name: clock
57 | url: "https://pub.dartlang.org"
58 | source: hosted
59 | version: "1.1.0"
60 | collection:
61 | dependency: transitive
62 | description:
63 | name: collection
64 | url: "https://pub.dartlang.org"
65 | source: hosted
66 | version: "1.16.0"
67 | convert:
68 | dependency: transitive
69 | description:
70 | name: convert
71 | url: "https://pub.dartlang.org"
72 | source: hosted
73 | version: "3.0.2"
74 | crypto:
75 | dependency: transitive
76 | description:
77 | name: crypto
78 | url: "https://pub.dartlang.org"
79 | source: hosted
80 | version: "3.0.2"
81 | cupertino_icons:
82 | dependency: "direct main"
83 | description:
84 | name: cupertino_icons
85 | url: "https://pub.dartlang.org"
86 | source: hosted
87 | version: "1.0.5"
88 | dart_style:
89 | dependency: transitive
90 | description:
91 | name: dart_style
92 | url: "https://pub.dartlang.org"
93 | source: hosted
94 | version: "2.2.3"
95 | device_frame:
96 | dependency: transitive
97 | description:
98 | name: device_frame
99 | url: "https://pub.dartlang.org"
100 | source: hosted
101 | version: "1.1.0"
102 | device_preview:
103 | dependency: "direct main"
104 | description:
105 | name: device_preview
106 | url: "https://pub.dartlang.org"
107 | source: hosted
108 | version: "1.1.0"
109 | fake_async:
110 | dependency: transitive
111 | description:
112 | name: fake_async
113 | url: "https://pub.dartlang.org"
114 | source: hosted
115 | version: "1.3.0"
116 | ffi:
117 | dependency: transitive
118 | description:
119 | name: ffi
120 | url: "https://pub.dartlang.org"
121 | source: hosted
122 | version: "2.0.1"
123 | file:
124 | dependency: transitive
125 | description:
126 | name: file
127 | url: "https://pub.dartlang.org"
128 | source: hosted
129 | version: "6.1.2"
130 | flutter:
131 | dependency: "direct main"
132 | description: flutter
133 | source: sdk
134 | version: "0.0.0"
135 | flutter_lints:
136 | dependency: "direct dev"
137 | description:
138 | name: flutter_lints
139 | url: "https://pub.dartlang.org"
140 | source: hosted
141 | version: "2.0.1"
142 | flutter_localizations:
143 | dependency: "direct main"
144 | description: flutter
145 | source: sdk
146 | version: "0.0.0"
147 | flutter_test:
148 | dependency: "direct dev"
149 | description: flutter
150 | source: sdk
151 | version: "0.0.0"
152 | flutter_web_plugins:
153 | dependency: transitive
154 | description: flutter
155 | source: sdk
156 | version: "0.0.0"
157 | freezed_annotation:
158 | dependency: transitive
159 | description:
160 | name: freezed_annotation
161 | url: "https://pub.dartlang.org"
162 | source: hosted
163 | version: "2.0.3"
164 | glob:
165 | dependency: transitive
166 | description:
167 | name: glob
168 | url: "https://pub.dartlang.org"
169 | source: hosted
170 | version: "2.1.0"
171 | intl:
172 | dependency: "direct main"
173 | description:
174 | name: intl
175 | url: "https://pub.dartlang.org"
176 | source: hosted
177 | version: "0.17.0"
178 | js:
179 | dependency: transitive
180 | description:
181 | name: js
182 | url: "https://pub.dartlang.org"
183 | source: hosted
184 | version: "0.6.4"
185 | json_annotation:
186 | dependency: transitive
187 | description:
188 | name: json_annotation
189 | url: "https://pub.dartlang.org"
190 | source: hosted
191 | version: "4.5.0"
192 | lints:
193 | dependency: transitive
194 | description:
195 | name: lints
196 | url: "https://pub.dartlang.org"
197 | source: hosted
198 | version: "2.0.0"
199 | matcher:
200 | dependency: transitive
201 | description:
202 | name: matcher
203 | url: "https://pub.dartlang.org"
204 | source: hosted
205 | version: "0.12.11"
206 | material_color_utilities:
207 | dependency: transitive
208 | description:
209 | name: material_color_utilities
210 | url: "https://pub.dartlang.org"
211 | source: hosted
212 | version: "0.1.4"
213 | meta:
214 | dependency: transitive
215 | description:
216 | name: meta
217 | url: "https://pub.dartlang.org"
218 | source: hosted
219 | version: "1.7.0"
220 | nested:
221 | dependency: transitive
222 | description:
223 | name: nested
224 | url: "https://pub.dartlang.org"
225 | source: hosted
226 | version: "1.0.0"
227 | package_config:
228 | dependency: transitive
229 | description:
230 | name: package_config
231 | url: "https://pub.dartlang.org"
232 | source: hosted
233 | version: "2.1.0"
234 | path:
235 | dependency: transitive
236 | description:
237 | name: path
238 | url: "https://pub.dartlang.org"
239 | source: hosted
240 | version: "1.8.1"
241 | path_provider_linux:
242 | dependency: transitive
243 | description:
244 | name: path_provider_linux
245 | url: "https://pub.dartlang.org"
246 | source: hosted
247 | version: "2.1.7"
248 | path_provider_platform_interface:
249 | dependency: transitive
250 | description:
251 | name: path_provider_platform_interface
252 | url: "https://pub.dartlang.org"
253 | source: hosted
254 | version: "2.0.4"
255 | path_provider_windows:
256 | dependency: transitive
257 | description:
258 | name: path_provider_windows
259 | url: "https://pub.dartlang.org"
260 | source: hosted
261 | version: "2.1.0"
262 | platform:
263 | dependency: transitive
264 | description:
265 | name: platform
266 | url: "https://pub.dartlang.org"
267 | source: hosted
268 | version: "3.1.0"
269 | plugin_platform_interface:
270 | dependency: transitive
271 | description:
272 | name: plugin_platform_interface
273 | url: "https://pub.dartlang.org"
274 | source: hosted
275 | version: "2.1.2"
276 | process:
277 | dependency: transitive
278 | description:
279 | name: process
280 | url: "https://pub.dartlang.org"
281 | source: hosted
282 | version: "4.2.4"
283 | provider:
284 | dependency: transitive
285 | description:
286 | name: provider
287 | url: "https://pub.dartlang.org"
288 | source: hosted
289 | version: "6.0.3"
290 | pub_semver:
291 | dependency: transitive
292 | description:
293 | name: pub_semver
294 | url: "https://pub.dartlang.org"
295 | source: hosted
296 | version: "2.1.1"
297 | shared_preferences:
298 | dependency: transitive
299 | description:
300 | name: shared_preferences
301 | url: "https://pub.dartlang.org"
302 | source: hosted
303 | version: "2.0.15"
304 | shared_preferences_android:
305 | dependency: transitive
306 | description:
307 | name: shared_preferences_android
308 | url: "https://pub.dartlang.org"
309 | source: hosted
310 | version: "2.0.12"
311 | shared_preferences_ios:
312 | dependency: transitive
313 | description:
314 | name: shared_preferences_ios
315 | url: "https://pub.dartlang.org"
316 | source: hosted
317 | version: "2.1.1"
318 | shared_preferences_linux:
319 | dependency: transitive
320 | description:
321 | name: shared_preferences_linux
322 | url: "https://pub.dartlang.org"
323 | source: hosted
324 | version: "2.1.1"
325 | shared_preferences_macos:
326 | dependency: transitive
327 | description:
328 | name: shared_preferences_macos
329 | url: "https://pub.dartlang.org"
330 | source: hosted
331 | version: "2.0.4"
332 | shared_preferences_platform_interface:
333 | dependency: transitive
334 | description:
335 | name: shared_preferences_platform_interface
336 | url: "https://pub.dartlang.org"
337 | source: hosted
338 | version: "2.0.0"
339 | shared_preferences_web:
340 | dependency: transitive
341 | description:
342 | name: shared_preferences_web
343 | url: "https://pub.dartlang.org"
344 | source: hosted
345 | version: "2.0.4"
346 | shared_preferences_windows:
347 | dependency: transitive
348 | description:
349 | name: shared_preferences_windows
350 | url: "https://pub.dartlang.org"
351 | source: hosted
352 | version: "2.1.1"
353 | sky_engine:
354 | dependency: transitive
355 | description: flutter
356 | source: sdk
357 | version: "0.0.99"
358 | source_span:
359 | dependency: transitive
360 | description:
361 | name: source_span
362 | url: "https://pub.dartlang.org"
363 | source: hosted
364 | version: "1.8.2"
365 | stack_trace:
366 | dependency: transitive
367 | description:
368 | name: stack_trace
369 | url: "https://pub.dartlang.org"
370 | source: hosted
371 | version: "1.10.0"
372 | stream_channel:
373 | dependency: transitive
374 | description:
375 | name: stream_channel
376 | url: "https://pub.dartlang.org"
377 | source: hosted
378 | version: "2.1.0"
379 | string_scanner:
380 | dependency: transitive
381 | description:
382 | name: string_scanner
383 | url: "https://pub.dartlang.org"
384 | source: hosted
385 | version: "1.1.0"
386 | term_glyph:
387 | dependency: transitive
388 | description:
389 | name: term_glyph
390 | url: "https://pub.dartlang.org"
391 | source: hosted
392 | version: "1.2.0"
393 | test_api:
394 | dependency: transitive
395 | description:
396 | name: test_api
397 | url: "https://pub.dartlang.org"
398 | source: hosted
399 | version: "0.4.9"
400 | typed_data:
401 | dependency: transitive
402 | description:
403 | name: typed_data
404 | url: "https://pub.dartlang.org"
405 | source: hosted
406 | version: "1.3.1"
407 | vector_math:
408 | dependency: transitive
409 | description:
410 | name: vector_math
411 | url: "https://pub.dartlang.org"
412 | source: hosted
413 | version: "2.1.2"
414 | watcher:
415 | dependency: transitive
416 | description:
417 | name: watcher
418 | url: "https://pub.dartlang.org"
419 | source: hosted
420 | version: "1.0.1"
421 | win32:
422 | dependency: transitive
423 | description:
424 | name: win32
425 | url: "https://pub.dartlang.org"
426 | source: hosted
427 | version: "2.7.0"
428 | xdg_directories:
429 | dependency: transitive
430 | description:
431 | name: xdg_directories
432 | url: "https://pub.dartlang.org"
433 | source: hosted
434 | version: "0.2.0+1"
435 | yalo:
436 | dependency: "direct main"
437 | description:
438 | path: ".."
439 | relative: true
440 | source: path
441 | version: "3.0.0"
442 | yalo_locale:
443 | dependency: "direct main"
444 | description:
445 | path: ".yalo_locale"
446 | relative: true
447 | source: path
448 | version: "1.0.0"
449 | yaml:
450 | dependency: transitive
451 | description:
452 | name: yaml
453 | url: "https://pub.dartlang.org"
454 | source: hosted
455 | version: "3.1.1"
456 | sdks:
457 | dart: ">=2.17.0 <3.0.0"
458 | flutter: ">=3.0.0"
459 |
--------------------------------------------------------------------------------
/.yalo_locale/lib/src/locale.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_localizations/flutter_localizations.dart';
2 | import 'package:flutter/widgets.dart';
3 | import 'package:intl/intl.dart';
4 |
5 | abstract class NamespacedZoneCheckout {
6 | T getContent(String key);
7 | String get title;
8 | }
9 |
10 | class EnNamespacedZoneCheckout extends NamespacedZoneCheckout {
11 | Map get _contentMap => {
12 | 'title': title,
13 | };
14 |
15 | @override
16 | T getContent(String key) {
17 | final Object? content = _contentMap[key];
18 | if (content is T) {
19 | return content;
20 | }
21 | throw Exception('Not found correct content of type "$T" by key "$key"');
22 | }
23 |
24 | /// Description: ""
25 | /// Example: "Checkout for additional page"
26 | @override
27 | final String title = Intl.message(
28 | '''Checkout for additional page''',
29 | name: 'title',
30 | desc: '',
31 | );
32 | }
33 |
34 | abstract class NamespacedZoneInnerNamespacedZone {
35 | T getContent(String key);
36 | String title({
37 | required String name,
38 | });
39 | String get description;
40 | String book(int howMany, {int? precision});
41 | }
42 |
43 | class EnNamespacedZoneInnerNamespacedZone extends NamespacedZoneInnerNamespacedZone {
44 | Map get _contentMap => {
45 | 'title': title,
46 | 'description': description,
47 | 'book': book,
48 | };
49 |
50 | @override
51 | T getContent(String key) {
52 | final Object? content = _contentMap[key];
53 | if (content is T) {
54 | return content;
55 | }
56 | throw Exception('Not found correct content of type "$T" by key "$key"');
57 | }
58 |
59 | /// Description: ""
60 | /// Example: "Deeper title of Inner namespaced zone with name $name"
61 | @override
62 | String title({
63 | required String name,
64 | }) =>
65 | Intl.message(
66 | '''Deeper title of Inner namespaced zone with name $name''',
67 | name: 'title',
68 | desc: '',
69 | );
70 |
71 | /// Description: ""
72 | /// Example: "Deeper description of Inner namespaced zone"
73 | @override
74 | final String description = Intl.message(
75 | '''Deeper description of Inner namespaced zone''',
76 | name: 'description',
77 | desc: '',
78 | );
79 |
80 | /// Description: "Uses for description of books count"
81 | /// Example: "zero: books, one: book, two: books, few: books, many: books, other: books"
82 | @override
83 | String book(int howMany, {int? precision}) => Intl.plural(
84 | howMany,
85 | name: '''book''',
86 | zero: '''books''',
87 | one: '''book''',
88 | two: '''books''',
89 | few: '''books''',
90 | many: '''books''',
91 | other: '''books''',
92 | desc: '''Uses for description of books count''',
93 | precision: precision,
94 | );
95 | }
96 |
97 | abstract class NamespacedZone {
98 | T getContent(String key);
99 | String get title;
100 | String get description;
101 | NamespacedZoneCheckout get checkout;
102 | NamespacedZoneInnerNamespacedZone get innerNamespacedZone;
103 | }
104 |
105 | class EnNamespacedZone extends NamespacedZone {
106 | Map get _contentMap => {
107 | 'title': title,
108 | 'description': description,
109 | 'checkout': checkout,
110 | 'innerNamespacedZone': innerNamespacedZone,
111 | };
112 |
113 | @override
114 | T getContent(String key) {
115 | final Object? content = _contentMap[key];
116 | if (content is T) {
117 | return content;
118 | }
119 | throw Exception('Not found correct content of type "$T" by key "$key"');
120 | }
121 |
122 | /// Description: ""
123 | /// Example: "Title of Namespaced zone"
124 | @override
125 | final String title = Intl.message(
126 | '''Title of Namespaced zone''',
127 | name: 'title',
128 | desc: '',
129 | );
130 |
131 | /// Description: ""
132 | /// Example: "Description of Namespaced zone"
133 | @override
134 | final String description = Intl.message(
135 | '''Description of Namespaced zone''',
136 | name: 'description',
137 | desc: '',
138 | );
139 | @override
140 | final NamespacedZoneCheckout checkout = EnNamespacedZoneCheckout();
141 | @override
142 | final NamespacedZoneInnerNamespacedZone innerNamespacedZone = EnNamespacedZoneInnerNamespacedZone();
143 | }
144 |
145 | abstract class App {
146 | T getContent(String key);
147 | String get title;
148 | String get description;
149 | }
150 |
151 | class EnApp extends App {
152 | Map get _contentMap => {
153 | 'title': title,
154 | 'description': description,
155 | };
156 |
157 | @override
158 | T getContent(String key) {
159 | final Object? content = _contentMap[key];
160 | if (content is T) {
161 | return content;
162 | }
163 | throw Exception('Not found correct content of type "$T" by key "$key"');
164 | }
165 |
166 | /// Description: ""
167 | /// Example: "Yalo app"
168 | @override
169 | final String title = Intl.message(
170 | '''Yalo app''',
171 | name: 'title',
172 | desc: '',
173 | );
174 |
175 | /// Description: ""
176 | /// Example: "This app will show you how to use yalo package"
177 | @override
178 | final String description = Intl.message(
179 | '''This app will show you how to use yalo package''',
180 | name: 'description',
181 | desc: '',
182 | );
183 | }
184 |
185 | abstract class CartCheckout {
186 | T getContent(String key);
187 | String get title;
188 | String get description;
189 | }
190 |
191 | class EnCartCheckout extends CartCheckout {
192 | Map get _contentMap => {
193 | 'title': title,
194 | 'description': description,
195 | };
196 |
197 | @override
198 | T getContent(String key) {
199 | final Object? content = _contentMap[key];
200 | if (content is T) {
201 | return content;
202 | }
203 | throw Exception('Not found correct content of type "$T" by key "$key"');
204 | }
205 |
206 | /// Description: ""
207 | /// Example: "Checkout"
208 | @override
209 | final String title = Intl.message(
210 | '''Checkout''',
211 | name: 'title',
212 | desc: '',
213 | );
214 |
215 | /// Description: ""
216 | /// Example: "You should checkout"
217 | @override
218 | final String description = Intl.message(
219 | '''You should checkout''',
220 | name: 'description',
221 | desc: '',
222 | );
223 | }
224 |
225 | abstract class Cart {
226 | T getContent(String key);
227 | String get title;
228 | String get description;
229 | CartCheckout get checkout;
230 | }
231 |
232 | class EnCart extends Cart {
233 | Map get _contentMap => {
234 | 'title': title,
235 | 'description': description,
236 | 'checkout': checkout,
237 | };
238 |
239 | @override
240 | T getContent(String key) {
241 | final Object? content = _contentMap[key];
242 | if (content is T) {
243 | return content;
244 | }
245 | throw Exception('Not found correct content of type "$T" by key "$key"');
246 | }
247 |
248 | /// Description: ""
249 | /// Example: "Cart"
250 | @override
251 | final String title = Intl.message(
252 | '''Cart''',
253 | name: 'title',
254 | desc: '',
255 | );
256 |
257 | /// Description: ""
258 | /// Example: "Please, fill the cart to do checkout"
259 | @override
260 | final String description = Intl.message(
261 | '''Please, fill the cart to do checkout''',
262 | name: 'description',
263 | desc: '',
264 | );
265 | @override
266 | final CartCheckout checkout = EnCartCheckout();
267 | }
268 |
269 | abstract class MainScreen {
270 | T getContent(String key);
271 | String product({
272 | required String brand,
273 | required int howMany,
274 | int? precision,
275 | });
276 | }
277 |
278 | class EnMainScreen extends MainScreen {
279 | Map get _contentMap => {
280 | 'product': product,
281 | };
282 |
283 | @override
284 | T getContent(String key) {
285 | final Object? content = _contentMap[key];
286 | if (content is T) {
287 | return content;
288 | }
289 | throw Exception('Not found correct content of type "$T" by key "$key"');
290 | }
291 |
292 | /// Description: ""
293 | /// Example: "zero: There no products., one: There is only one product left from the brand $brand., two: It is your last chance to buy product from the $brand., few: null, many: null, other: You can buy $howMany products"
294 | @override
295 | String product({
296 | required String brand,
297 | required int howMany,
298 | int? precision,
299 | }) =>
300 | Intl.plural(
301 | howMany,
302 | name: '''product''',
303 | zero: '''There no products.''',
304 | one: '''There is only one product left from the brand $brand.''',
305 | two: '''It is your last chance to buy product from the $brand.''',
306 | few: '''You can buy $howMany products''',
307 | many: '''You can buy $howMany products''',
308 | other: '''You can buy $howMany products''',
309 | desc: '''''',
310 | precision: precision,
311 | );
312 | }
313 |
314 | abstract class LocalizationMessages {
315 | T getContent(String key);
316 | String get cancel;
317 | String get save;
318 | String book(int howMany, {int? precision});
319 | NamespacedZone get namespacedZone;
320 | App get app;
321 | Cart get cart;
322 | String people(int howMany, {int? precision});
323 | String greetings({
324 | required String userName,
325 | required String hotelName,
326 | });
327 | String weather({
328 | required String temperature,
329 | });
330 | String shop({
331 | required String shopName,
332 | required int howMany,
333 | required String city,
334 | int? precision,
335 | });
336 | MainScreen get mainScreen;
337 | }
338 |
339 | class En extends LocalizationMessages {
340 | Map get _contentMap => {
341 | 'cancel': cancel,
342 | 'save': save,
343 | 'book': book,
344 | 'namespacedZone': namespacedZone,
345 | 'app': app,
346 | 'cart': cart,
347 | 'people': people,
348 | 'greetings': greetings,
349 | 'weather': weather,
350 | 'shop': shop,
351 | 'mainScreen': mainScreen,
352 | };
353 |
354 | @override
355 | T getContent(String key) {
356 | final Object? content = _contentMap[key];
357 | if (content is T) {
358 | return content;
359 | }
360 | throw Exception('Not found correct content of type "$T" by key "$key"');
361 | }
362 |
363 | /// Description: ""
364 | /// Example: "Cancel"
365 | @override
366 | final String cancel = Intl.message(
367 | '''Cancel''',
368 | name: 'cancel',
369 | desc: '',
370 | );
371 |
372 | /// Description: "Saving something"
373 | /// Example: "Save"
374 | @override
375 | final String save = Intl.message(
376 | '''Save''',
377 | name: 'save',
378 | desc: 'Saving something',
379 | );
380 |
381 | /// Description: "Uses for description of books count"
382 | /// Example: "zero: books, one: book, two: books, few: null, many: null, other: books"
383 | @override
384 | String book(int howMany, {int? precision}) => Intl.plural(
385 | howMany,
386 | name: '''book''',
387 | zero: '''books''',
388 | one: '''book''',
389 | two: '''books''',
390 | few: '''books''',
391 | many: '''books''',
392 | other: '''books''',
393 | desc: '''Uses for description of books count''',
394 | precision: precision,
395 | );
396 | @override
397 | final NamespacedZone namespacedZone = EnNamespacedZone();
398 | @override
399 | final App app = EnApp();
400 | @override
401 | final Cart cart = EnCart();
402 |
403 | /// Description: "An example with numeric substitution in plural strings"
404 | /// Example: "zero: I saw no people there, one: I saw only one man there, two: I saw two people there, few: I saw $howMany people there, many: I saw $howMany or more people there, other: I think, I saw $howMany people there"
405 | @override
406 | String people(int howMany, {int? precision}) => Intl.plural(
407 | howMany,
408 | name: '''people''',
409 | zero: '''I saw no people there''',
410 | one: '''I saw only one man there''',
411 | two: '''I saw two people there''',
412 | few: '''I saw $howMany people there''',
413 | many: '''I saw $howMany or more people there''',
414 | other: '''I think, I saw $howMany people there''',
415 | desc: '''An example with numeric substitution in plural strings''',
416 | precision: precision,
417 | );
418 |
419 | /// Description: ""
420 | /// Example: "Hello $userName! We are glad to see you at our $hotelName hotel!"
421 | @override
422 | String greetings({
423 | required String userName,
424 | required String hotelName,
425 | }) =>
426 | Intl.message(
427 | '''Hello $userName! We are glad to see you at our $hotelName hotel!''',
428 | name: 'greetings',
429 | desc: '',
430 | );
431 |
432 | /// Description: "Title on the main weather screen (see here: https://www.figma.com/community/file/974352831498882628)"
433 | /// Example: "It's $temperature degrees outside today!"
434 | @override
435 | String weather({
436 | required String temperature,
437 | }) =>
438 | Intl.message(
439 | '''It's $temperature degrees outside today!''',
440 | name: 'weather',
441 | desc: 'Title on the main weather screen (see here: https://www.figma.com/community/file/974352831498882628)',
442 | );
443 |
444 | /// Description: ""
445 | /// Example: "zero: There are no any $shopName shops, one: There are exactly one $shopName shop, two: There are two $shopName shops, few: There are $howMany $shopName shops and we have plans to open additional at the $city!, many: There are $howMany shops. Sorry, I didn't remember that shop name., other: Well, I tired to count these shops. I can say that there are only $howMany shops!"
446 | @override
447 | String shop({
448 | required String shopName,
449 | required int howMany,
450 | required String city,
451 | int? precision,
452 | }) =>
453 | Intl.plural(
454 | howMany,
455 | name: '''shop''',
456 | zero: '''There are no any $shopName shops''',
457 | one: '''There are exactly one $shopName shop''',
458 | two: '''There are two $shopName shops''',
459 | few: '''There are $howMany $shopName shops and we have plans to open additional at the $city!''',
460 | many: '''There are $howMany shops. Sorry, I didn't remember that shop name.''',
461 | other: '''Well, I tired to count these shops. I can say that there are only $howMany shops!''',
462 | desc: '''''',
463 | precision: precision,
464 | );
465 | @override
466 | final MainScreen mainScreen = EnMainScreen();
467 | }
468 |
469 | class LocalizationDelegate extends LocalizationsDelegate {
470 | @override
471 | bool isSupported(Locale locale) => _languageMap.keys.contains(locale.languageCode);
472 |
473 | @override
474 | Future load(Locale locale) async {
475 | Intl.defaultLocale = locale.countryCode == null ? locale.languageCode : locale.toString();
476 | return _languageMap[locale.languageCode]!;
477 | }
478 |
479 | @override
480 | bool shouldReload(LocalizationsDelegate old) => false;
481 |
482 | final Map _languageMap = {
483 | 'en': En(),
484 | };
485 | }
486 |
487 | class Messages {
488 | static LocalizationMessages of(BuildContext context) => Localizations.of(context, LocalizationMessages);
489 |
490 | static LocalizationMessages get en => LocalizationDelegate()._languageMap['en']!;
491 | }
492 |
493 | final List localizationsDelegates = [
494 | LocalizationDelegate(),
495 | ...GlobalMaterialLocalizations.delegates
496 | ];
497 |
498 | const List supportedLocales = [
499 | Locale('en'),
500 | ];
501 |
--------------------------------------------------------------------------------