From 7ac327e11a9cdce7c1aef6a5d2092971dc117975 Mon Sep 17 00:00:00 2001 From: alireza easazade Date: Fri, 15 Sep 2023 21:34:46 +0330 Subject: [PATCH] Fix localized generators generating in english instead of localized --- lib/src/base/registered_data_sources.dart | 258 +++++++++++++--------- scripts/register_data_sources.dart | 2 +- test/manual/fa_ir/paragraph_test.dart | 1 - 3 files changed, 155 insertions(+), 106 deletions(-) diff --git a/lib/src/base/registered_data_sources.dart b/lib/src/base/registered_data_sources.dart index bff8627..38b5482 100644 --- a/lib/src/base/registered_data_sources.dart +++ b/lib/src/base/registered_data_sources.dart @@ -50,134 +50,184 @@ import 'package:faker_x/src/locales/fa_ir/datasources/lorem.dart' as lorem_817; final Map> registeredDataSources = { Locales.en_us: { // en_us.address has 14 DataSources - DataKeys.address: address_237.address, - DataKeys.building_number: address_237.building_number, - DataKeys.city_name: address_237.city_name, - DataKeys.city_prefix: address_237.city_prefix, - DataKeys.city_suffix: address_237.city_suffix, - DataKeys.neighborhood: address_237.neighborhood, - DataKeys.postcode: address_237.postcode, - DataKeys.postcode_format: address_237.postcode_format, - DataKeys.secondary_address: address_237.secondary_address, - DataKeys.state: address_237.state, - DataKeys.state_abbr: address_237.state_abbr, - DataKeys.street_address: address_237.street_address, - DataKeys.street_name: address_237.street_name, - DataKeys.street_suffix: address_237.street_suffix, + DataKeys.address: address_237.address.copyWith(locale: Locales.en_us), + DataKeys.building_number: + address_237.building_number.copyWith(locale: Locales.en_us), + DataKeys.city_name: address_237.city_name.copyWith(locale: Locales.en_us), + DataKeys.city_prefix: + address_237.city_prefix.copyWith(locale: Locales.en_us), + DataKeys.city_suffix: + address_237.city_suffix.copyWith(locale: Locales.en_us), + DataKeys.neighborhood: + address_237.neighborhood.copyWith(locale: Locales.en_us), + DataKeys.postcode: address_237.postcode.copyWith(locale: Locales.en_us), + DataKeys.postcode_format: + address_237.postcode_format.copyWith(locale: Locales.en_us), + DataKeys.secondary_address: + address_237.secondary_address.copyWith(locale: Locales.en_us), + DataKeys.state: address_237.state.copyWith(locale: Locales.en_us), + DataKeys.state_abbr: address_237.state_abbr.copyWith(locale: Locales.en_us), + DataKeys.street_address: + address_237.street_address.copyWith(locale: Locales.en_us), + DataKeys.street_name: + address_237.street_name.copyWith(locale: Locales.en_us), + DataKeys.street_suffix: + address_237.street_suffix.copyWith(locale: Locales.en_us), // en_us.animal has 1 DataSources - DataKeys.animal_name: animal_354.animal_name, + DataKeys.animal_name: + animal_354.animal_name.copyWith(locale: Locales.en_us), // en_us.vehicle has 1 DataSources - DataKeys.car: vehicle_661.car, + DataKeys.car: vehicle_661.car.copyWith(locale: Locales.en_us), // en_us.color has 2 DataSources - DataKeys.color_hex: color_257.color_hex, - DataKeys.color_name: color_180.color_name, + DataKeys.color_hex: color_257.color_hex.copyWith(locale: Locales.en_us), + DataKeys.color_name: color_180.color_name.copyWith(locale: Locales.en_us), // en_us.person has 7 DataSources - DataKeys.first_name_en: person_886.first_name_en, - DataKeys.last_name_en: person_886.last_name_en, - DataKeys.first_name: person_873.first_name, - DataKeys.first_name_female: person_873.first_name_female, - DataKeys.first_name_male: person_873.first_name_male, - DataKeys.full_name: person_873.full_name, - DataKeys.last_name: person_873.last_name, + DataKeys.first_name_en: + person_886.first_name_en.copyWith(locale: Locales.en_us), + DataKeys.last_name_en: + person_886.last_name_en.copyWith(locale: Locales.en_us), + DataKeys.first_name: person_873.first_name.copyWith(locale: Locales.en_us), + DataKeys.first_name_female: + person_873.first_name_female.copyWith(locale: Locales.en_us), + DataKeys.first_name_male: + person_873.first_name_male.copyWith(locale: Locales.en_us), + DataKeys.full_name: person_873.full_name.copyWith(locale: Locales.en_us), + DataKeys.last_name: person_873.last_name.copyWith(locale: Locales.en_us), // en_us.phone has 2 DataSources - DataKeys.international_phone_number: phone_59.international_phone_number, - DataKeys.phone_number: phone_59.phone_number, + DataKeys.international_phone_number: + phone_59.international_phone_number.copyWith(locale: Locales.en_us), + DataKeys.phone_number: + phone_59.phone_number.copyWith(locale: Locales.en_us), // en_us.job has 3 DataSources - DataKeys.job_prefix: job_914.job_prefix, - DataKeys.job_suffix: job_914.job_suffix, - DataKeys.job_title: job_914.job_title, + DataKeys.job_prefix: job_914.job_prefix.copyWith(locale: Locales.en_us), + DataKeys.job_suffix: job_914.job_suffix.copyWith(locale: Locales.en_us), + DataKeys.job_title: job_914.job_title.copyWith(locale: Locales.en_us), // en_us.automotive has 1 DataSources - DataKeys.license_plate: automotive_744.license_plate, + DataKeys.license_plate: + automotive_744.license_plate.copyWith(locale: Locales.en_us), // en_us.lorem has 3 DataSources - DataKeys.paragraph: lorem_536.paragraph, - DataKeys.sentence: lorem_915.sentence, - DataKeys.word: lorem_915.word, + DataKeys.paragraph: lorem_536.paragraph.copyWith(locale: Locales.en_us), + DataKeys.sentence: lorem_915.sentence.copyWith(locale: Locales.en_us), + DataKeys.word: lorem_915.word.copyWith(locale: Locales.en_us), // en_us.image has 2 DataSources - DataKeys.avatar_uri: image_121.avatar_uri, - DataKeys.image: image_121.image, + DataKeys.avatar_uri: image_121.avatar_uri.copyWith(locale: Locales.en_us), + DataKeys.image: image_121.image.copyWith(locale: Locales.en_us), // en_us.internet has 18 DataSources - DataKeys.disposable_email: internet_824.disposable_email, - DataKeys.disposable_mail_provider: internet_824.disposable_mail_provider, - DataKeys.domain_name: internet_824.domain_name, - DataKeys.domain_suffixes: internet_824.domain_suffixes, - DataKeys.email: internet_824.email, - DataKeys.email_from: internet_824.email_from, - DataKeys.emoji: internet_824.emoji, - DataKeys.http_url: internet_824.http_url, - DataKeys.https_url: internet_824.https_url, - DataKeys.ipv4: internet_824.ipv4, - DataKeys.ipv6: internet_824.ipv6, - DataKeys.mac_address: internet_824.mac_address, - DataKeys.mail_provider: internet_824.mail_provider, - DataKeys.password: internet_824.password, - DataKeys.safe_email: internet_824.safe_email, - DataKeys.uri: internet_824.uri, - DataKeys.user_name: internet_824.user_name, - DataKeys.user_name_from: internet_824.user_name_from, + DataKeys.disposable_email: + internet_824.disposable_email.copyWith(locale: Locales.en_us), + DataKeys.disposable_mail_provider: + internet_824.disposable_mail_provider.copyWith(locale: Locales.en_us), + DataKeys.domain_name: + internet_824.domain_name.copyWith(locale: Locales.en_us), + DataKeys.domain_suffixes: + internet_824.domain_suffixes.copyWith(locale: Locales.en_us), + DataKeys.email: internet_824.email.copyWith(locale: Locales.en_us), + DataKeys.email_from: + internet_824.email_from.copyWith(locale: Locales.en_us), + DataKeys.emoji: internet_824.emoji.copyWith(locale: Locales.en_us), + DataKeys.http_url: internet_824.http_url.copyWith(locale: Locales.en_us), + DataKeys.https_url: internet_824.https_url.copyWith(locale: Locales.en_us), + DataKeys.ipv4: internet_824.ipv4.copyWith(locale: Locales.en_us), + DataKeys.ipv6: internet_824.ipv6.copyWith(locale: Locales.en_us), + DataKeys.mac_address: + internet_824.mac_address.copyWith(locale: Locales.en_us), + DataKeys.mail_provider: + internet_824.mail_provider.copyWith(locale: Locales.en_us), + DataKeys.password: internet_824.password.copyWith(locale: Locales.en_us), + DataKeys.safe_email: + internet_824.safe_email.copyWith(locale: Locales.en_us), + DataKeys.uri: internet_824.uri.copyWith(locale: Locales.en_us), + DataKeys.user_name: internet_824.user_name.copyWith(locale: Locales.en_us), + DataKeys.user_name_from: + internet_824.user_name_from.copyWith(locale: Locales.en_us), // en_us.location has 1 DataSources - DataKeys.geo_location: location_711.geo_location, + DataKeys.geo_location: + location_711.geo_location.copyWith(locale: Locales.en_us), }, Locales.fa_ir: { // fa_ir.address has 10 DataSources - DataKeys.address: address_449.address, - DataKeys.alley: address_449.alley, - DataKeys.building_name: address_449.building_name, - DataKeys.building_number: address_449.building_number, - DataKeys.city_name: address_449.city_name, - DataKeys.postcode: address_449.postcode, - DataKeys.state: address_449.state, - DataKeys.street_name: address_449.street_name, - DataKeys.street_prefix: address_449.street_prefix, - DataKeys.street_suffix: address_449.street_suffix, + DataKeys.address: address_449.address.copyWith(locale: Locales.fa_ir), + DataKeys.alley: address_449.alley.copyWith(locale: Locales.fa_ir), + DataKeys.building_name: + address_449.building_name.copyWith(locale: Locales.fa_ir), + DataKeys.building_number: + address_449.building_number.copyWith(locale: Locales.fa_ir), + DataKeys.city_name: address_449.city_name.copyWith(locale: Locales.fa_ir), + DataKeys.postcode: address_449.postcode.copyWith(locale: Locales.fa_ir), + DataKeys.state: address_449.state.copyWith(locale: Locales.fa_ir), + DataKeys.street_name: + address_449.street_name.copyWith(locale: Locales.fa_ir), + DataKeys.street_prefix: + address_449.street_prefix.copyWith(locale: Locales.fa_ir), + DataKeys.street_suffix: + address_449.street_suffix.copyWith(locale: Locales.fa_ir), // fa_ir.animal has 1 DataSources - DataKeys.animal_name: animal_679.animal_name, + DataKeys.animal_name: + animal_679.animal_name.copyWith(locale: Locales.fa_ir), // fa_ir.vehicle has 1 DataSources - DataKeys.car: vehicle_225.car, + DataKeys.car: vehicle_225.car.copyWith(locale: Locales.fa_ir), // fa_ir.color has 2 DataSources - DataKeys.color_hex: color_257.color_hex, - DataKeys.color_name: color_783.color_name, + DataKeys.color_hex: color_257.color_hex.copyWith(locale: Locales.fa_ir), + DataKeys.color_name: color_783.color_name.copyWith(locale: Locales.fa_ir), // fa_ir.person has 7 DataSources - DataKeys.first_name_en: person_886.first_name_en, - DataKeys.last_name_en: person_886.last_name_en, - DataKeys.first_name: person_378.first_name, - DataKeys.first_name_female: person_378.first_name_female, - DataKeys.first_name_male: person_378.first_name_male, - DataKeys.full_name: person_378.full_name, - DataKeys.last_name: person_378.last_name, + DataKeys.first_name_en: + person_886.first_name_en.copyWith(locale: Locales.fa_ir), + DataKeys.last_name_en: + person_886.last_name_en.copyWith(locale: Locales.fa_ir), + DataKeys.first_name: person_378.first_name.copyWith(locale: Locales.fa_ir), + DataKeys.first_name_female: + person_378.first_name_female.copyWith(locale: Locales.fa_ir), + DataKeys.first_name_male: + person_378.first_name_male.copyWith(locale: Locales.fa_ir), + DataKeys.full_name: person_378.full_name.copyWith(locale: Locales.fa_ir), + DataKeys.last_name: person_378.last_name.copyWith(locale: Locales.fa_ir), // fa_ir.phone has 2 DataSources - DataKeys.international_phone_number: phone_653.international_phone_number, - DataKeys.phone_number: phone_653.phone_number, + DataKeys.international_phone_number: + phone_653.international_phone_number.copyWith(locale: Locales.fa_ir), + DataKeys.phone_number: + phone_653.phone_number.copyWith(locale: Locales.fa_ir), // fa_ir.job has 1 DataSources - DataKeys.job_title: job_938.job_title, + DataKeys.job_title: job_938.job_title.copyWith(locale: Locales.fa_ir), // fa_ir.automotive has 1 DataSources - DataKeys.license_plate: automotive_31.license_plate, + DataKeys.license_plate: + automotive_31.license_plate.copyWith(locale: Locales.fa_ir), // fa_ir.lorem has 3 DataSources - DataKeys.paragraph: lorem_536.paragraph, - DataKeys.sentence: lorem_817.sentence, - DataKeys.word: lorem_817.word, + DataKeys.paragraph: lorem_536.paragraph.copyWith(locale: Locales.fa_ir), + DataKeys.sentence: lorem_817.sentence.copyWith(locale: Locales.fa_ir), + DataKeys.word: lorem_817.word.copyWith(locale: Locales.fa_ir), // fa_ir.image has 2 DataSources - DataKeys.avatar_uri: image_121.avatar_uri, - DataKeys.image: image_121.image, + DataKeys.avatar_uri: image_121.avatar_uri.copyWith(locale: Locales.fa_ir), + DataKeys.image: image_121.image.copyWith(locale: Locales.fa_ir), // fa_ir.internet has 18 DataSources - DataKeys.disposable_email: internet_824.disposable_email, - DataKeys.disposable_mail_provider: internet_824.disposable_mail_provider, - DataKeys.domain_name: internet_824.domain_name, - DataKeys.domain_suffixes: internet_824.domain_suffixes, - DataKeys.email: internet_824.email, - DataKeys.email_from: internet_824.email_from, - DataKeys.emoji: internet_824.emoji, - DataKeys.http_url: internet_824.http_url, - DataKeys.https_url: internet_824.https_url, - DataKeys.ipv4: internet_824.ipv4, - DataKeys.ipv6: internet_824.ipv6, - DataKeys.mac_address: internet_824.mac_address, - DataKeys.mail_provider: internet_824.mail_provider, - DataKeys.password: internet_824.password, - DataKeys.safe_email: internet_824.safe_email, - DataKeys.uri: internet_824.uri, - DataKeys.user_name: internet_824.user_name, - DataKeys.user_name_from: internet_824.user_name_from, + DataKeys.disposable_email: + internet_824.disposable_email.copyWith(locale: Locales.fa_ir), + DataKeys.disposable_mail_provider: + internet_824.disposable_mail_provider.copyWith(locale: Locales.fa_ir), + DataKeys.domain_name: + internet_824.domain_name.copyWith(locale: Locales.fa_ir), + DataKeys.domain_suffixes: + internet_824.domain_suffixes.copyWith(locale: Locales.fa_ir), + DataKeys.email: internet_824.email.copyWith(locale: Locales.fa_ir), + DataKeys.email_from: + internet_824.email_from.copyWith(locale: Locales.fa_ir), + DataKeys.emoji: internet_824.emoji.copyWith(locale: Locales.fa_ir), + DataKeys.http_url: internet_824.http_url.copyWith(locale: Locales.fa_ir), + DataKeys.https_url: internet_824.https_url.copyWith(locale: Locales.fa_ir), + DataKeys.ipv4: internet_824.ipv4.copyWith(locale: Locales.fa_ir), + DataKeys.ipv6: internet_824.ipv6.copyWith(locale: Locales.fa_ir), + DataKeys.mac_address: + internet_824.mac_address.copyWith(locale: Locales.fa_ir), + DataKeys.mail_provider: + internet_824.mail_provider.copyWith(locale: Locales.fa_ir), + DataKeys.password: internet_824.password.copyWith(locale: Locales.fa_ir), + DataKeys.safe_email: + internet_824.safe_email.copyWith(locale: Locales.fa_ir), + DataKeys.uri: internet_824.uri.copyWith(locale: Locales.fa_ir), + DataKeys.user_name: internet_824.user_name.copyWith(locale: Locales.fa_ir), + DataKeys.user_name_from: + internet_824.user_name_from.copyWith(locale: Locales.fa_ir), // fa_ir.location has 1 DataSources - DataKeys.geo_location: location_711.geo_location, + DataKeys.geo_location: + location_711.geo_location.copyWith(locale: Locales.fa_ir), }, }; diff --git a/scripts/register_data_sources.dart b/scripts/register_data_sources.dart index d6657df..a83964e 100644 --- a/scripts/register_data_sources.dart +++ b/scripts/register_data_sources.dart @@ -57,7 +57,7 @@ import 'package:faker_x/src/base/locale.dart'; ' // $locale.$resourceName has ${dsInfoEntry.value.length} DataSources'); for (var dsInfo in dsInfos) { buffer.writeln( - 'DataKeys.${dsInfo.dataSource.dataKey.toString()} : ${dsInfo.directiveRef}.${dsInfo.varName},'); + 'DataKeys.${dsInfo.dataSource.dataKey} : ${dsInfo.directiveRef}.${dsInfo.varName}.copyWith(locale: Locales.$locale),'); } } buffer.writeln('},'); diff --git a/test/manual/fa_ir/paragraph_test.dart b/test/manual/fa_ir/paragraph_test.dart index 1f8c979..916fb96 100644 --- a/test/manual/fa_ir/paragraph_test.dart +++ b/test/manual/fa_ir/paragraph_test.dart @@ -8,7 +8,6 @@ import '../../utils.dart'; void main() { test("fa_ir -> lorem -> paragraph test", () async { for (var i = 0; i < testRepeatCount; i++) { - final sentence = FakerX.localized.fa_ir.lorem.sentence; assertFakeValue(FakerX.localized.fa_ir.lorem.paragraph(maxSentences: 4)); } });