Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Please consider providing a small utility to work with dart strings #22

Open
neiljaywarner opened this issue Jul 28, 2023 · 1 comment

Comments

@neiljaywarner
Copy link

Please consider lettign us use this outside of arb/csv files, but instead with strings/text widgets.

for example, suppose we are using
Text('hi');
and for whatever reason we are not quite ready to use arb type localization and/or for whatever reason are not using a localization library/package that works quite the same way.

Could we please have the option to use 'hi'.psuedo() and translate to a psuedo string, perhaps with sane defaults for first pass, then configurable just like your yaml file for second pass?
thanks

@defuncart
Copy link
Owner

defuncart commented Jul 29, 2023

Hi @neiljaywarner, this is a use case I never actually thought of and haven't needed myself. In feature/call-pseudo-directly-on-strings I've put together a very quick & dirty POC.

If you dependent on flutter_pseudolocalizor as a dependency (as opposed to dev_dependency as normal) from git

flutter_pseudolocalizor:
    git:
      url: https://github.com/defuncart/flutter_pseudolocalizor
      ref: feature/call-pseudo-directly-on-strings

you can set set the settings using

FlutterPseudolocalizor.settings = const FlutterPseudolocalizorSettings(
      languageToGenerate: SupportedLanguage.de,
      useBrackets: false,
      textExpansionRate: 1,
);

and use as follows

'Hello World'.pseudo()

As mentioned, this is very quick & dirty, nevertheless it works and can be experimented on :)

Let me know what you think. There is no EDD on when this would ship on pub: the existing api will need to be updated, however the POC branch should work just fine.

Full Example
import 'package:flutter/material.dart';
import 'package:flutter_pseudolocalizor/flutter_pseudolocalizor.dart';

void main() {
FlutterPseudolocalizor.settings = const FlutterPseudolocalizorSettings(
  languageToGenerate: SupportedLanguage.de,
  useBrackets: false,
  textExpansionRate: 1,
);

runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
  return MaterialApp(
    home: Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Text(
          'Hello World'.pseudo(),
        ),
      ),
    ),
  );
}
}

Simulator Screen Shot - iPhone 13 mini - 2023-07-29 at 12 00 52

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

No branches or pull requests

2 participants