Fakery icon indicating copy to clipboard operation
Fakery copied to clipboard

I keep getting `JSON file for 'de' locale was not found.` for every locale I enter.

Open jaunruh opened this issue 6 years ago • 9 comments

I am working with Server Side Swift and want to use Fakery for testing. But no matter what locale I use, I keep getting a JSON file for 'de' locale was not found. error. I installed Fakery via the Swift Package Manager using the Package.swift file.

jaunruh avatar Sep 23 '19 09:09 jaunruh

That's because the JSON file is not included as SwiftPM currently does not support resources. The Config-struct is a little "under-documented" at the moment. It's possible to set paths inside of this before creating an instance of Faker.

Config.dirResourcePath = "Foo/Bar"
let faker = Faker(locale: "de")

If your are building a command line tool you could use an argument to have a dynamic way to specify a location.

ricobeck avatar Nov 14 '19 19:11 ricobeck

What does "Foo/Bar" represent here? Should I be mimicking the "Resource/Locales/[locale].json" structure somewhere or am I supposed to be referring to the package dependency?

hennessyevan avatar Mar 23 '20 23:03 hennessyevan

I have the same issue with SPM in Xcode 11. I know this is an issue of SPM itself that doesn't use ressource of packages, but, is it possible to document a workaround ? Maybe based on providing json files ourselves to Fakery

zarghol avatar Mar 26 '20 15:03 zarghol

I hate it, but here's a fix that worked for me:

import Fakery

func fixFakery() {
  guard
    let xcodeProductsPath = ProcessInfo.processInfo.environment["__XCODE_BUILT_PRODUCTS_DIR_PATHS"]
  else {
    fatalError("Can't fix Fakery Locales path because found no __XCODE_BUILT_PRODUCTS_DIR_PATHS env var.")
  }
  Config.dirResourcePath = xcodeProductsPath + "/../../../SourcePackages/checkouts/Fakery/Resources/Locales"
}

And then I call it before initializing Faker() instance, like this:

class StringFieldTests: XCTestCase {
  let faker: Faker = {
    fixFakery()
    return Faker()
  }()
}

dsabanin avatar Apr 24 '20 21:04 dsabanin

I've started a PR which addresses this. You can specify a file path in the initialiser. Check the notes for todos and pitch in, if you have a spare hour.

let locale = "en"
let stringPath = Bundle.main.path(forResource: locale, ofType: "json")
let faker = Faker(locale: locale, path: stringPath!)

#137

morgz avatar Jun 19 '20 14:06 morgz

Hey guys, as SwiftPM is now supporting resources in the current beta, I have posted a PR that fixes this issue properly for anyone who's using Fakery via SwiftPM in Swift 5.3 onwards (no custom path needed!): https://github.com/vadymmarkov/Fakery/pull/138

Jeehut avatar Jul 08 '20 07:07 Jeehut

Any idea when that PR may be accepted? It's been over 1 month.

mrlynn avatar Aug 10 '20 22:08 mrlynn

I'm ready to accept as soon as my comments in https://github.com/vadymmarkov/Fakery/pull/138 will be addressed.

vadymmarkov avatar Aug 13 '20 16:08 vadymmarkov