Git Product home page Git Product logo

Comments (7)

Tienisto avatar Tienisto commented on May 21, 2024

Hi,

Did you configure key_case: camel? Then the maps should also follow the case:

key_case: camel
key_map_case: pascal
flat_map: false
maps:
  - projectActivityType
  - addressBookType

from slang.

vladaman avatar vladaman commented on May 21, 2024

Thanks, but still doesn't seem to work as we expect. With following example we'd expect the flat map will be generted just for maps mentioned in the list. Neither of them work. None of the maps is generated. We'd expect the regular keys be converted into camel case, and maps for these objects generated with Pascal case.

          key_case: camel
          key_map_case: pascal
          flat_map: false
          maps:
            - ProjectActivityType
            - AddressBookType
            - addressBookType

from slang.

Tienisto avatar Tienisto commented on May 21, 2024

You mean this following map?

AppLocale.cs: {
  'addressBookType.company': 'Firma',
  'addressBookType.person': 'Osoba',
}

Then flat_map needs to be true. The flat map is the map containing all translations regardless of "map" or "not map".
It is the one-dimensional map (hence flat) for all translations.

Actually, I don't know exactly what you are going to do... If you want to access the keys dynamically, then this should be enough:

final t = Translations.of(context);
String a = t.projectActivityType['Company']; // Company because pascal case is applied

Just to make sure: key_map_case applies to all keys inside a map, key_case applies to all other keys, therefore also to all map parents like addressBookType.

from slang.

Tienisto avatar Tienisto commented on May 21, 2024

It seems to be alright on my side.

from slang.

vladaman avatar vladaman commented on May 21, 2024

Sorry @Tienisto , but I am still having issues. My config is:

key_case: camel
key_map_case: snake
flat_map: true
maps:
   - ProjectActivityType
   - AddressBookType
   - FieldType

But unfortunately the maps in strings.g.dart are still translated to:

'fieldType.lplate': 'License plate',
'fieldType.desc': 'Description',
'fieldType.contactInvestor': 'Contact Investor',

In .json file we have following:

"FieldType": {
 "LPLATE": "License plate",
 "DESC": "Description",
 "CONTACT_INVESTOR": "Contact Investor",

I would expect the map keys to be in snake case but it's not. But our use case is different. We'd like to use camel case but ONLY for maps to disable any text transformations. Reason is we use enums like:

// The key will be "FieldType.LPLATE"
labelText: t[FieldType.LPLATE.toString()]

from slang.

Tienisto avatar Tienisto commented on May 21, 2024

Alright,

currently, it is not possible to have different cases.

key_map_case only applies to local maps (i.e. t.error['camel_case']).

I think a new configuration flat_map_key_case should be implemented.

from slang.

Tienisto avatar Tienisto commented on May 21, 2024

I think there is no elegant solution for your problem.

FieldType.LPLATE.toString() will be probably calculated as FieldType.LPLATE. This string contains 2 different cases.

The best solution would be to use the new dart enum feature: FieldType.LPLATE.name. Then you will get LPLATE.

Then use the following config:

key_case: pascal
# do not set key_map_case, so we retain the UPPERCASE_SNAKE case
maps:
  - FieldType

Will generate:

Map<String, String> get FieldType => {
	'LPLATE': 'License plate',
	'DESC': 'Description',
	'CONTACT_INVESTOR': 'Contact Investor',
};

Usage:

String a = t.FieldType['CONTACT_INVESTOR'];
String b = t.FieldType[FieldType.LPLATE.name];

from slang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.