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

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

Open
jaunruh opened this issue Sep 23, 2019 · 8 comments

Comments

@jaunruh
Copy link

jaunruh commented Sep 23, 2019

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.

@ricobeck
Copy link

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.

@hennessyevan
Copy link

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?

@zarghol
Copy link

zarghol commented Mar 26, 2020

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

@dsabanin
Copy link

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()
  }()
}

@morgz
Copy link

morgz commented Jun 19, 2020

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

@Jeehut
Copy link

Jeehut commented Jul 8, 2020

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!): #138

@mrlynn
Copy link

mrlynn commented Aug 10, 2020

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

@vadymmarkov
Copy link
Owner

vadymmarkov commented Aug 13, 2020

I'm ready to accept as soon as my comments in #138 will be addressed.

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

Successfully merging a pull request may close this issue.

9 participants