Comments (7)
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.
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.
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.
It seems to be alright on my side.
from slang.
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.
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.
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)
- slang_gpt duplicate keys when there are modifiers HOT 1
- Remote loading of localization HOT 1
- Newlines are lost when overriding translations HOT 7
- Arabic translations glitch HOT 2
- How to use dynamic strings HOT 4
- Automatic translation with ChatGPT HOT 2
- [Analyze] RichText json key re-appreared regardless translated in all locales in _missing_translations_...json file HOT 1
- What is the better way to provide translation across app in a multiple plugin project? HOT 1
- Setting base_locale HOT 2
- Could slang works with showTimePicker & showDatePicker? HOT 1
- Upon upgrading Flutter from version 3.13.4 to 3.19.4, specifying only variables as values in JSON ceased to convert them to strings. HOT 1
- Support enumName without case conversion HOT 1
- Running slang apply duplicates map HOT 2
- Sort input files before generating translations HOT 1
- TranslationProvider does not recreate childs
- Support ARB placeholder types HOT 1
- A modifier works like 'rich' in pure dart
- [slang_gpt] Add support to Gpt 4 Turbo
- Add Documentation comments to the generated translation file HOT 1
- Fallback to the language code? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.