I keep getting `JSON file for 'de' locale was not found.` for every locale I enter.
Opened this issue · 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.
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.
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?
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
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()
}()
}
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!)
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
Any idea when that PR may be accepted? It's been over 1 month.
I'm ready to accept as soon as my comments in #138 will be addressed.
was this ever accepted? its been 5 years.