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

Add locale awareness #44

Closed
wants to merge 3 commits into from
Closed

Add locale awareness #44

wants to merge 3 commits into from

Conversation

mark-careplanner
Copy link

Adds locale awareness to Faker factory method instantiation call.

@Warxcell
Copy link

I wouldn't do it like that. It's ugly to use $_SERVER variables either it's a standart variable. And language cannot be changed per column basis.

   private static $generators = [];

   private function getGenerator($locale = null) {
      if($locale === null) {
          return self::$generator;
      }
      if(!isset(self::$generators[$locale])) {
          self::$generators[$locale] = Factory::create($locale);
      }
     retirm self::$generators[$locale];
   }

   public function getValue($expression)
    {
        $locale = isset($expression['locale']) ? $expression['locale'] : null;
        return self::getGenerator($locale)->format(self::$formatterTansformerMap[$expression['formatter']]);
    }

And if possible somehow to pass the variable through the constructor for default generator.

@mark-careplanner
Copy link
Author

Understood. How would you recommend getting hold of the locale variable if we don't use $_SERVER?

@Warxcell
Copy link

Warxcell commented Sep 18, 2019

In the example I gave - you can pass the locale within the configuration of columns. If you don't pass - it will use english.

"table": {
    "telephone": {"formatter":"phoneNumber", "locale": "en"}
}

@mark-careplanner
Copy link
Author

That's a good suggestion. The only trouble is I think you've proposed this fix against your forked version, not the base version, correct? What is happening with maintenance of this project now? Do you have merge permissions?

@Warxcell
Copy link

Nope. I will soon release my own fork built around symfony (but can be used standalone also). It already includes locale-awareness.

@mark-careplanner
Copy link
Author

mark-careplanner commented Sep 19, 2019

Ah! Exciting! I will check out your version - let me know when it goes live!

@Warxcell
Copy link

@mark-careplanner mark-careplanner closed this by deleting the head repository Sep 5, 2023
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 this pull request may close these issues.

2 participants