-
Notifications
You must be signed in to change notification settings - Fork 84
Configuration
The config file config/laravel-translation-manager.php
has comments that provide a description
for each option. Note that when admin_enabled
is set to false
then translation management is
limited to editing existing translations all other operations have to be done through the
command line. Ideally, this option needs to be dynamic based on user privileges so that
translators cannot delete translations or administer translations but admins can. See
Installation: step 8.
By default the primary locale is en
. The primary locale determines what language is used for
the source text for the translate button in the edit pop-up and can be changed in the web
interface for the current session. When editing the text for the primary locale a button in the
edit pop-up allows you to convert the text of the key to a default value (change . - _ to
spaces, capitalize first letter of each word) that way you can generate descent placeholder text
to continue development and replace it with more meaningful value later.
By default the configuration will load all translations found in the standard Laravel locations.
Below {vendor}
, {package}
, {locale}
, {group}
are placeholders for their corresponding
values referring to vendor name, package name, locale string and translation group. The
translation group will consist of optional sub-directory tree and the file name, allowing you to
organize your translation files.
/resources/lang/{locale}/{group}.php
: Standard project translation files
/resources/lang/vendor/{package}/{locale}/{group}
: Package translation override files.
/workbench/{vendor}/{package}/resources/lang/{locale}/{group}
: Translation files for packages that you are developing in the current project. Laravel 4.2
style but the directory layout updated to version 5 standard. These will have a group prefix
of wbn:
in the database and web interface to distinguish them from the standard Laravel
package namespaces.
/vendor/{vendor}/{package}/resources/lang/{locale}/{group}
: Translation files for packages that are dependents of your project. By default no
translation files are loaded from this section. You will need to edit the configuration file
for the 'vendor' section and list the packages you want to include in the 'include' array in
the form 'vendor/package'. These will have a group prefix of vnd:
in the database and web
interface to distinguish them from the standard Laravel package namespaces
The default configuration file also has entries for two packages whose translation files'
location and naming convention does not follow Laravel conventions and require more tweaking to
allow import/export of their language files. These non-standard layouts can only be included in
the wbn:
or vnd:
prefixed namespaces.
If you published the views to your project in Installation: step 11 then
you can customize them to your liking. The package view directory also contains a
layouts/master.blade.php
file for a default layout. The intent is for you to provide your own
master layout that the index.blade.php will extend so it can match your site's style.
By default users that have translation access who are not administrators, ie.
UserCan::admin_translations
returns true
, can modify all locales.
To enable per locale access control for these users you need to set user_locales_enabled
in
the configuration file to true
and configure per user locales in the ltm_user_locales
table.
The user locales are indexed by currently logged in user's id.
You will also need to define a user list provider in the config file. It is a Closure
that
returns an array of objects with id
, email
and name
fields that will be displayed in the
web UI.
The default definition assumes that the Auth::user()
returns an eloquent model for the user
and uses the currently logged in user instance to get an array of all users.
You will to modify this definition to only return a list of users that have access to the
translation manager web UI. Please keep in mind that by a user can modify any locale if there is
no entry for this user in the ltm_user_locales
table or if the entry is null or empty. By this
measure the table contains entries for users wih limited access.
/**
* Closure used to retrieve a list of users for per user locale management
* Only used if user_locales_enabled is true
*
* Default definition will retrieve all records using the object returned by
* Auth::user(). It is assumed that it is a Model.
*
* Only id, email and optional name are used.
*
* This should be modified to return only users who have access to the
* translation manager web UI.
*
* @type Closure returning an array of Objects with id, email and optional name
*
* @param $user Illuminate\Database\Eloquent\Model
* @param $connection string
*/
'user_list_provider' => function ($user, $connection_name) {
/* @var $connection_name string */
/* @var $user Illuminate\Database\Eloquent\Model */
/* @var $query Illuminate\Database\Eloquent\Builder */
$query = $user->on($connection_name);
return $query->orderby('id')->get(['id', 'email']);
},
NOTE If the user id is not found in the table or if the locales
list is null or empty
then the user will have access to all locales.
Column | Type | Description |
---|---|---|
user_id |
unsigned integer |
value returned by Auth::id()
|
locales |
text |
comma separated list of locales the user is allowed to modify. null or an empty string means can modify any locale. |
Users who do not have access to a locale will not be allowed to modify its translations. They will see these translations as text instead of a link that opens the edit pop-up.
If you have your translation table(s) in a database other than the default used by the default connection you will need to define another database connection that has this database as the default and define a default connection to use the for translation manager database access. By default this is will be the default database connection defined in your Laravel database config file.
Laravel 5 does not handle changing the connection's database consistently. Previous attempts to allow overriding the database name via the config file produced inconsistent results.
/**
* used to provide an alternate default connection name for translation
* tables
*
* @type string connection name to use for the default connection
*
* if blank, null or not defined then default connection will be used.
*
*/
'default_connection' => 'mysql_laravel5',
If you want to be able to access multiple databases for the translation manager from one set of
language files you can configure the db_connections
option in the config file. Here is what I
use to access the production server's translations from my local development environment:
/**
* @type array list of alternate database connections and their properties indexed by app()->environment() value,
* default connection settings are taken from config, so only add alternate connections
*
* If user_list_connection is missing, null or empty then the connection will also be used
* to obtain the user list for user locale management
*
* If user_list_provider is missing then the globally defined user_list_provider will be used for that connection.
*
* description is used to display the connection name, default connection is displayed as 'default' in
* the web interface.
*
* indatabase_publish of:
* 0 - means use files only and publish to files.
* 1 - means use cache for publishing modifications. No files are written out
* 2 - means use cache for publishing modifications but also write out the files.
* useful for publishing to files while leaving all flags in the database as
* they would be after publishing only to cache.
*/
'db_connections' => array(
'local' => array(
'mysql_prd' => array(
'description' => 'production',
'indatabase_publish' => 2,
//'user_list_connection' => '',
//'user_list_provider' => function ($user, $connection_name) {
// /* @var $connection_name string */
// /* @var $user Illuminate\Database\Eloquent\Model */
// /* @var $query Illuminate\Database\Eloquent\Builder */
// $query = $user->on($connection_name);
// return $query->orderby('id')->get(['id', 'email']);
// },
),
),
),
The option is an array of environment names which in turn contain database connection names which list the options to use for that connection.
description
: the string to use in the web interface combo box to represent this connection. If the
description is empty or missing then the connection name will be used.
indatabase_publish
: the setting for indatabase_publish
to use for this connection. If this option is missing
then the global configuration indatabase_publish
will be used. Setting this value to 2,
will write to the local translation files but leave the database in a state to serve changed
translations from the cache. Note that with indatabase_publish
set to 1 or 2 publishing
will not reset the changed flag for translations and these will continue to show up in the
dashboard as changed
.
- 0: use files only and publish to files.
- 1: use cache for publishing modifications. No files are written out
- 2: use cache for publishing modifications but also write out the files. Useful for
publishing to files while leaving all flags in the database as they would be after
publishing only to cache.
user_list_provider
: definition of a closure to use for managing per locale user access on this connection. If
this entry is missing then the globally defined user_list_provider
will be used for that
connection. Only used if user_locales_enabled
is true.
user_list_connection
: the connection name to use for this connection when retrieving the user list for user access
admin. If this entry is missing, null or an empty string then the connection name used for
translation manager tables will be used for user list retrieval. Only used if
user_locales_enabled
is true.
-
After updating the remote translations you need to go into translations page on the remote server and do a
publish all
so that either the files or the cache is updated with new translations. -
After deploying a new version of the application, with updated translation files on the servers, you should do an
Import
withOnly add new translations
. This will import any new translations and reset the cache.