smartnsoft / flappytranslator Goto Github PK
View Code? Open in Web Editor NEWA tool which automatically generates Flutter localization resources from CSV and Excel files.
License: MIT License
A tool which automatically generates Flutter localization resources from CSV and Excel files.
License: MIT License
Hey there so there's this application that I am building that is meant to relay information in a number of languages given that it's to serve a country of multi languages and while some languages will come off as easy e.g. Swahili, English, kinyarwanda, Arabic etc... There are some languages that don't have common language codes...
So I was wondering if this package will be able to run with languages where I am able to provide all the translations but don't have language codes (can I be able to define my own codes)
PS some of these are languages supported by Google even in search?
Hi there,
I've use this plugin for several months now with no issues. However, I recently encounter some problems. When I try to generate the dart file, it will be generated on the root directory instead of the designated output path & the generated file now doesn't follow the values set on the pubspec.yaml (I set depend_on_context as false but the file now do depend on context). Is there any solution for this problem?
Thank you very much for this super simple translation solution.
We need to support countries where more than one language is spoken. For example Switzerland:
german: de-CH
french: fr-CH
italian: it-CH
Kind regards,
Sörnt
In the generated map of translations, the varible name is defined as:
static Map<String, String> _en_USValues = {
however this generated the following info/issue in dart analyser:
info: Name non-constant identifiers using lowerCamelCase. (non_constant_identifier_names at ...
Can we add an option to remove the underscore in the ${lang} name ?
I was thinking, that it would be nice to have a feature, that can automatically translate and insert missing translations into our translation file. I have a similar workflow set up, since I often have to translate into languages I dont speak. Do you think this would be something that fits into the scope of this library ? If so, then I could implement it and send you a PR for it. Otherwise I'm just going to put it into a seperate package.
When I'm running the command I'm getting the following error:
C:\develop\projects\helpdesk\app\helpdesk>flutter pub run flappy_translator
[PROGRESS] 1 words recognized
Unhandled exception:
RangeError (index): Invalid value: Valid value range is empty: 0
#0 List.[] (dart:core-patch/growable_array.dart:149:60)
#1 FlappyTranslator.generate (package:flappy_translator/flappy_translator.dart:113:39)
#2 main (file:///c:/develop/soft/flutter/.pub-cache/hosted/pub.dartlang.org/flappy_translator-1.2.2/bin/flappy_translator.dart:58:20)
#3 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
pub finished with exit code 255
Settings are placed in the pubspec.yaml file and are default from the readme page. What I'm doing wrong?
flutter pub run flappy_translator
result is error.
Unhandled exception:
Could not format because the source could not be parsed:
line 15, column 34: Expected to find ';'.
╷
15 │ static Map<String, String> _zh-cnValues = {
│ ^^^
╵
line 15, column 37: Operator declarations must be preceded by the keyword 'operator'.
╷
15 │ static Map<String, String> _zh-cnValues = {
│ ^
╵
line 15, column 37: Methods must have an explicit list of parameters.
╷
15 │ static Map<String, String> _zh-cnValues = {
│ ^
╵
line 15, column 38: A function body must be provided.
╷
15 │ static Map<String, String> _zh-cnValues = {
│ ^^^^^^^^
╵
line 15, column 38: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
╷
15 │ static Map<String, String> _zh-cnValues = {
│ ^^^^^^^^
╵
line 18, column 34: Expected to find ';'.
╷
18 │ static Map<String, String> _zh-twValues = {
│ ^^^
╵
line 18, column 37: Operator declarations must be preceded by the keyword 'operator'.
╷
18 │ static Map<String, String> _zh-twValues = {
│ ^
╵
line 18, column 37: Methods must have an explicit list of parameters.
╷
18 │ static Map<String, String> _zh-twValues = {
│ ^
╵
line 18, column 38: A function body must be provided.
╷
18 │ static Map<String, String> _zh-twValues = {
│ ^^^^^^^^
╵
line 18, column 38: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
╷
18 │ static Map<String, String> _zh-twValues = {
│ ^^^^^^^^
╵
#0 ErrorListener.throwIfErrors (package:dart_style/src/error_listener.dart:28:5)
#1 DartFormatter.formatSource (package:dart_style/src/dart_formatter.dart:149:19)
#2 DartFormatter.format (package:dart_style/src/dart_formatter.dart:76:12)
#3 FlappyTranslator._writeInFile (package:flappy_translator/flappy_translator.dart:153:32)
#4 FlappyTranslator.generate (package:flappy_translator/flappy_translator.dart:146:5)
#5 main (file:///Users/keyeMyria/.pub-cache/hosted/pub.flutter-io.cn/flappy_translator-1.2.2/bin/flappy_translator.dart:58:20)
#6 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#7 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
Could you add the second command too in Readme?
pub run flappy_translator translation.csv
Could not find a file named "pubspec.yaml" in "/Users/apple/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-2.1.0".
So I used Flutter pub and it works.
% flutter pub run flappy_translator translation.csv
[PROGRESS] 1 words recognized
Hi,
Thanks for this tools. It's just perfect but in the last version I get some error in the generated code when I add a variable in the string.
For example:
If I put this entry in my CSV file:
"ble_device_incompatible","Your device is not compatible with your mask %1$s.","Votre appareil n'est pas compatible avec votre masque %1$s."
The result is:
static String ble_device_incompatible({
required String var1,
}) =>
_getText("ble_device_incompatible").replaceAll("%1\$s", var1);
The @ before "required" word is missing.
Do you need more information about my configuration?
Regards,
Daniel
Please, I need to get the localized version of a key contained in a String
Strings.of(context).currentLocale
doesn't get updated and always returns "en"
after changing the locale by calling:
Strings.load(Locale("ar"))
Hi Thomas. Thanks again for creating flappy_translator. Could you please upload a license so that everyone who uses the package knows what license the software is registered under? Thanks, James.
As seen in #17, a csv of the type
keys;en-gb;en-us
test;Colour!Color
results in flappy_translator not being able to generate localizations. Although en-gb is incorrect (as noted in the documentation), a check when parsing the csv would be good, thus logging an error and terminating code generation.
It is outside the scope of this issue whether the locale is valid. For instance, as in #23, non-valid locales may be desired.
Once the dependencies dart_style and excel are migrated to null safety, then flappy_translator will also be migrated.
Related issues:
excel - Null safety migration
dart_style - Migrate to null safety
The String I set in my CSV file comes by calling I18n.of(context).noEmail but it is cut in the middle of one word and the rest is in the new line. It should wrap the text, and move whole word as it is when I hardcoded String and display it i the same place.
I did some tests with two the same Strings - one from I18n.of(context).noEmail and the second one I hardcoded in my Widget, so it's the same two Strings. When I want to display it in normal Text Widget the first one is not wrapped by contrast to the second one.
Hi, I've just started to use this in my flutter app, but I wanted to be able to let the user choose the locale. If I create a dropdown list of supported locales how can I get I18n/I18nDelegate to reload for that locale? I've tried:
Ì18n.load(Locale("fr"));
but this does not work.
Hi,
So I used flappy_translator in two ways and the two ways throw different errors:
For this case (notice the list for supportedLocales):
import 'package:bonfire/i18n.dart';
import 'package:bonfire/pages/splash/index.dart';
import 'package:bonfire/route_generator.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MaterialApp(
title: 'App name',
localizationsDelegates: [
const I18nDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en, ''),
const Locale('fr', ''),
],
theme: ThemeData(),
home: SplashPage(),
initialRoute: '/',
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}
it throws:
The method 'contains' was called on null.
Receiver: null
Tried calling: contains(Instance of 'Locale')
Apparently in this line:
@override
bool isSupported(Locale locale) => supportedLocals.contains(locale);
the Set supportedLocals is null when contains is called
for this case (notice **supportedLocales has changed):
import 'package:bonfire/i18n.dart';
import 'package:bonfire/pages/splash/index.dart';
import 'package:bonfire/route_generator.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MaterialApp(
title: 'Bonfire',
localizationsDelegates: [
const I18nDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: I18nDelegate.supportedLocals,
theme: ThemeData(),
home: SplashPage(),
initialRoute: '/',
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}
it throws this error:
'package:flutter/src/widgets/app.dart': Failed assertion: line 219 pos 15: 'supportedLocales != null && supportedLocales.isNotEmpty': is not true.
and honestly, for this one, I really can't find out what's wrong.
Do you have any idea?
Ignore or fix :
sort_constructors_first
always_specify_types
Fix :
prefer_const_constructors
static final Set<Locale> supportedLocals = {
Locale('en', 'US'),
Locale('fr', 'FR'),
};
Regards
change: static Map<String, Map<String, String>> _allValues ---> static final Map<String, Map<String, String>> allValues
so that we can get strings in any locale from allValues.
My code:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import './i18n.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var i18n = I18n.of(context);
return MaterialApp(
title: i18n.appTitle,
supportedLocales: I18nDelegate.supportedLocals,
initialRoute: '',
routes: [],
);
}
}
I'm getting the following exception when running it:
I/flutter ( 5741): The getter 'appTitle' was called on null.
What I'm doing wrong?
Hi there,
I just realised my app is still using the dependency override from git, since the package has not been updated yet.
Do you plan on creating a new release for the latest features ?
First of all, congrats for the idea and the package. I specially like the idea of having the translations available at compile time.
It doesn't seem to be able to handle plurals though. Is it planned?
b get Running "flutter pub get" in jaysecurity... Because no versions of flappy_translator match >2.0.0-nullsafety.3 <3.0.0 and flappy_translator 2.0.0-nullsafety.3 depends on excel ^2.0.0-null-safety-3, flappy_translator ^2.0.0-nullsafety.3 requires excel ^2.0.0-null-safety-3. And because no versions of excel match >2.0.0-null-safety-3 <3.0.0, flappy_translator ^2.0.0-nullsafety.3 requires excel 2.0.0-null-safety-3. And because excel 2.0.0-null-safety-3 depends on xml ^5.0.2 and flutter_svg >=1.1.0 depends on xml ^6.0.1, flappy_translator ^2.0.0-nullsafety.3 is incompatible with flutter_svg >=1.1.0. So, because jaysecurity depends on both flutter_svg ^1.1.1+1 and flappy_translator ^2.0.0-nullsafety.3, version solving failed. pub get failed (1; So, because jaysecurity depends on both flutter_svg ^1.1.1+1 and flappy_translator ^2.0.0-nullsafety.3, version solving failed.)
Hi. Can you explain why to use depend_on_context: True (pros/cons)? And how to use library when this option is set to False?
For a loca strings of the form
test;My var: %do$d
test2;Another var: %new$d
...
code generator will fail as the variable name is a reserved keyword in dart. Thus, before generating methods for a loca string with a variable, the variable name should be tested to ensure that it is not a reserved keyword.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.