3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Core_BAO_Translation
extends CRM_Core_DAO_Translation
{
20 * Get a list of valid statuses for translated-strings.
24 public static function getStatuses($context = NULL) {
26 ['id' => 1, 'name' => 'active', 'label' => ts('Active')],
27 ['id' => 2, 'name' => 'draft', 'label' => ts('Draft')],
29 return self
::formatPsuedoconstant($context, $options);
33 * Get a list of tables with translatable strings.
36 * Ex: ['civicrm_event' => 'civicrm_event']
38 public static function getEntityTables() {
39 if (!isset(Civi
::$statics[__CLASS__
]['allTables'])) {
40 $tables = array_keys(self
::getTranslatedFields());
41 Civi
::$statics[__CLASS__
]['allTables'] = array_combine($tables, $tables);
43 return Civi
::$statics[__CLASS__
]['allTables'];
47 * Get a list of fields with translatable strings.
50 * Ex: ['title' => 'title', 'description' => 'description']
52 public static function getEntityFields() {
53 if (!isset(Civi
::$statics[__CLASS__
]['allFields'])) {
55 foreach (self
::getTranslatedFields() as $columns) {
56 foreach ($columns as $column => $sqlExpr) {
57 $allFields[$column] = $column;
60 Civi
::$statics[__CLASS__
]['allFields'] = $allFields;
62 return Civi
::$statics[__CLASS__
]['allFields'];
66 * Given a constant list of of id/name/label options, convert to the
67 * format required by pseudoconstant.
69 * @param string|NULL $context
70 * @param array $options
71 * List of options, each as a record of id+name+label.
72 * Ex: [['id' => 123, 'name' => 'foo_bar', 'label' => 'Foo Bar']]
76 private static function formatPsuedoconstant($context, array $options) {
77 // https://docs.civicrm.org/dev/en/latest/framework/pseudoconstant/#context
78 $key = ($context === 'match') ?
'name' : 'id';
79 $value = ($context === 'validate') ?
'name' : 'label';
80 return array_combine(array_column($options, $key), array_column($options, $value));
85 * List of data fields to translate, organized by table and column.
86 * Omitted/unlisted fields are not translated. Any listed field may be translated.
87 * Values should be TRUE.
88 * Ex: $fields['civicrm_event']['summary'] = TRUE
90 public static function getTranslatedFields() {
91 $key = 'translatedFields';
92 $cache = Civi
::cache('fields');
93 if (($r = $cache->get($key)) !== NULL) {
98 \CRM_Utils_Hook
::translateFields($f);
100 // Future: Assimilate defaults originating in XML (incl extension-entities)
101 // e.g. CRM_Core_I18n_SchemaStructure::columns() will grab core fields
103 $cache->set($key, $f);