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

Please support string translations #143

Open
divdax opened this issue Sep 26, 2018 · 1 comment
Open

Please support string translations #143

divdax opened this issue Sep 26, 2018 · 1 comment

Comments

@divdax
Copy link
Contributor

divdax commented Sep 26, 2018

Would be nice to manage string translations in database with this package instead of using json files.
https://laravel.com/docs/5.7/localization#using-translation-strings-as-keys

Translations with group and item column feels very weird.

@GainsNetwork
Copy link

GainsNetwork commented Jan 8, 2019

Hey I don't know if it can help you but I managed to translate directly the strings by creating the following helper :

<?php

use \Waavi\Translation\Models\Translation;

function translate($string, $params = []){

	try{

		$translation = Translation::where('item', $string)->where('locale', App::getLocale())->first()->text;

		foreach($params as $key => $value){
			$translation = str_replace(':'.$key, $value, $translation);
		}

	}catch(\Exception $e){

		return '"'.$string.'"'." has no translation";

	}
	return $translation;
}

function reverseTranslate($string){
	
	return Translation::where('text', $string)->first()->item;
	
}

?>

Then you only need to create a service provider like this :

...
public function register(){
         require_once app_path('Helpers/TranslationHelper.php');
}

And you can use it in every view / controller!

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

No branches or pull requests

2 participants