This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
localization.html
122 lines (109 loc) · 32.2 KB
/
localization.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Localization | Sanjab</title>
<meta name="generator" content="VuePress 1.5.4">
<link rel="icon" href="/images/favicon.ico">
<meta name="description" content="Sanjab is an admin package for laravel framework. create admin panels quick and extendiable.">
<meta property="og:site_name" content="Sanjab">
<meta property="og:title" content="Localization">
<meta property="og:type" content="website">
<meta property="og:url" content="/localization.html">
<meta name="twitter:title" content="Localization">
<meta name="twitter:url" content="/localization.html">
<meta name="twitter:card" content="summary_large_image">
<link rel="preload" href="/assets/css/0.styles.2e8fc617.css" as="style"><link rel="preload" href="/assets/js/app.bb080b10.js" as="script"><link rel="preload" href="/assets/js/3.0ca36dc4.js" as="script"><link rel="preload" href="/assets/js/46.22ab45aa.js" as="script"><link rel="prefetch" href="/assets/js/10.f2fbcc00.js"><link rel="prefetch" href="/assets/js/11.a88150f7.js"><link rel="prefetch" href="/assets/js/12.3f4fc49f.js"><link rel="prefetch" href="/assets/js/13.2f7bbe92.js"><link rel="prefetch" href="/assets/js/14.f69c3be7.js"><link rel="prefetch" href="/assets/js/15.146fd77b.js"><link rel="prefetch" href="/assets/js/16.7040661a.js"><link rel="prefetch" href="/assets/js/17.10c67635.js"><link rel="prefetch" href="/assets/js/18.b258fc52.js"><link rel="prefetch" href="/assets/js/19.0d164613.js"><link rel="prefetch" href="/assets/js/20.2cf36932.js"><link rel="prefetch" href="/assets/js/21.8f19317a.js"><link rel="prefetch" href="/assets/js/22.3dc04c9b.js"><link rel="prefetch" href="/assets/js/23.7d93154e.js"><link rel="prefetch" href="/assets/js/24.d10068db.js"><link rel="prefetch" href="/assets/js/25.ecd8acc3.js"><link rel="prefetch" href="/assets/js/26.5ae91a18.js"><link rel="prefetch" href="/assets/js/27.1ae60bea.js"><link rel="prefetch" href="/assets/js/28.1dd28706.js"><link rel="prefetch" href="/assets/js/29.8c489115.js"><link rel="prefetch" href="/assets/js/30.effa9b52.js"><link rel="prefetch" href="/assets/js/31.5f330bfc.js"><link rel="prefetch" href="/assets/js/32.4ac193d2.js"><link rel="prefetch" href="/assets/js/33.afce904a.js"><link rel="prefetch" href="/assets/js/34.29769f89.js"><link rel="prefetch" href="/assets/js/35.85aef861.js"><link rel="prefetch" href="/assets/js/36.5b05176c.js"><link rel="prefetch" href="/assets/js/37.40a67162.js"><link rel="prefetch" href="/assets/js/38.0585aaff.js"><link rel="prefetch" href="/assets/js/39.085c73ff.js"><link rel="prefetch" href="/assets/js/4.fb05333f.js"><link rel="prefetch" href="/assets/js/40.667cd531.js"><link rel="prefetch" href="/assets/js/41.9bf9596e.js"><link rel="prefetch" href="/assets/js/42.7bf6bc5a.js"><link rel="prefetch" href="/assets/js/43.dbde9849.js"><link rel="prefetch" href="/assets/js/44.a1a7fab3.js"><link rel="prefetch" href="/assets/js/45.af6c374b.js"><link rel="prefetch" href="/assets/js/47.095fc7de.js"><link rel="prefetch" href="/assets/js/48.fafabd31.js"><link rel="prefetch" href="/assets/js/49.8b56a6bd.js"><link rel="prefetch" href="/assets/js/5.57d9df4b.js"><link rel="prefetch" href="/assets/js/50.523e948d.js"><link rel="prefetch" href="/assets/js/51.2b0f3efa.js"><link rel="prefetch" href="/assets/js/6.3a56987d.js"><link rel="prefetch" href="/assets/js/7.8bfd5ac9.js"><link rel="prefetch" href="/assets/js/8.3d2834af.js"><link rel="prefetch" href="/assets/js/9.e3de8168.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.26dc1fe9.js">
<link rel="stylesheet" href="/assets/css/0.styles.2e8fc617.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/logo.svg" alt="Sanjab" class="logo"> <span class="site-name can-hide">Sanjab</span></a> <div class="links"><form id="search-form" role="search" class="algolia-search-wrapper search-box"><input id="algolia-search-input" class="search-query"></form> <nav class="nav-links can-hide"><div class="nav-item"><a href="https://discord.gg/kwuTZQd" target="_blank" rel="noopener noreferrer" class="nav-link external">
Discussion
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <a href="https://github.com/sanjabteam/sanjab" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="https://discord.gg/kwuTZQd" target="_blank" rel="noopener noreferrer" class="nav-link external">
Discussion
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <a href="https://github.com/sanjabteam/sanjab" target="_blank" rel="noopener noreferrer" class="repo-link">
GitHub
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <ul class="sidebar-links"><li><a href="/" aria-current="page" class="sidebar-link">Sanjab</a></li><li><a href="/install.html" class="sidebar-link">Installation</a></li><li><a href="/crud.html" class="sidebar-link">CRUD</a></li><li><a href="/setting.html" class="sidebar-link">Setting</a></li><li><section class="sidebar-group collapsable depth-0"><a href="/widgets" class="sidebar-heading clickable"><span>Widgets</span> <span class="arrow right"></span></a> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><a href="/cards" class="sidebar-heading clickable"><span>Cards</span> <span class="arrow right"></span></a> <!----></section></li><li><a href="/actions.html" class="sidebar-link">Actions</a></li><li><a href="/localization.html" aria-current="page" class="active sidebar-link">Localization</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/localization.html#languages" class="sidebar-link">Languages</a></li><li class="sidebar-sub-header"><a href="/localization.html#multilingual-crud" class="sidebar-link">Multilingual CRUD</a></li><li class="sidebar-sub-header"><a href="/localization.html#multilingual-setting" class="sidebar-link">Multilingual Setting</a></li></ul></li><li><a href="/authorization.html" class="sidebar-link">Authorization</a></li><li><a href="/compile.html" class="sidebar-link">Custom compile</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="localization"><a href="#localization" class="header-anchor">#</a> Localization</h1> <ul><li><a href="#languages">Languages</a></li> <li><a href="#multilingual-crud">Multilingual CRUD</a> <ul><li><a href="#example">Example</a></li></ul></li> <li><a href="#multilingual-setting">Multilingual Setting</a> <ul><li><a href="#access-to-setting-values">Access To setting values</a></li> <li><a href="#set-settings-programmatically">Set settings programmatically</a></li></ul></li></ul> <p>You can have multilingual inputs for your models and settings.</p> <p>Multilingual is based on <a href="https://github.com/Astrotomic/laravel-translatable" target="_blank" rel="noopener noreferrer">Laravel Translatable<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>.</p> <h2 id="languages"><a href="#languages" class="header-anchor">#</a> Languages</h2> <p>To set available languages for translation you should change <code>locales</code> in <code>config/sanjab.php</code>:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token single-quoted-string string">'locales'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">[</span>
<span class="token single-quoted-string string">'en'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'English'</span><span class="token punctuation">,</span>
<span class="token single-quoted-string string">'fr'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'French'</span><span class="token punctuation">,</span>
<span class="token single-quoted-string string">'fa'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'فارسی'</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">,</span>
</code></pre></div><p>And also need set laravel translatable configuration.</p> <div class="language-bash extra-class"><pre class="language-bash"><code>php artisan vendor:publish --tag<span class="token operator">=</span>translatable
</code></pre></div><p>and in <code>config/translatable.php</code>:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token single-quoted-string string">'locales'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">[</span>
<span class="token single-quoted-string string">'en'</span><span class="token punctuation">,</span>
<span class="token single-quoted-string string">'fr'</span><span class="token punctuation">,</span>
<span class="token single-quoted-string string">'fa'</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">,</span>
</code></pre></div><blockquote><p>Note: Difference between <code>config/translatable.php</code> and <code>config/sanjab.php</code>.</p> <p>in <code>config/translatable.php</code> you should just set locale codes, but in <code>config/sanjab.php</code> you should set locale code and locale title in array key and value. ('locale_code' => 'Locale Title').</p></blockquote> <h2 id="multilingual-crud"><a href="#multilingual-crud" class="header-anchor">#</a> Multilingual CRUD</h2> <p>As mentioned in <a href="https://github.com/Astrotomic/laravel-translatable" target="_blank" rel="noopener noreferrer">Laravel Translatable<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> docs you need two models.</p> <p>one for non-multilingual attributes and one for multilingual attributes. these have a one-to-many relationship.</p> <h3 id="example"><a href="#example" class="header-anchor">#</a> Example</h3> <p>Category.php:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">use</span> <span class="token package">Astrotomic<span class="token punctuation">\</span>Translatable<span class="token punctuation">\</span>Translatable</span><span class="token punctuation">;</span>
<span class="token keyword">class</span> <span class="token class-name">Category</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span>
<span class="token punctuation">{</span>
<span class="token keyword">use</span> <span class="token package">Translatable</span><span class="token punctuation">;</span>
<span class="token keyword">protected</span> <span class="token variable">$fillable</span> <span class="token operator">=</span> <span class="token punctuation">[</span>
<span class="token single-quoted-string string">'image'</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">protected</span> <span class="token variable">$translatedAttributes</span> <span class="token operator">=</span> <span class="token punctuation">[</span>
<span class="token single-quoted-string string">'name'</span> <span class="token punctuation">,</span>
<span class="token single-quoted-string string">'description'</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">protected</span> <span class="token variable">$with</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token single-quoted-string string">'translations'</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// optional</span>
<span class="token punctuation">}</span>
</code></pre></div><p>CategoryTranslation.php:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">class</span> <span class="token class-name">CategoryTranslation</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span>
<span class="token punctuation">{</span>
<span class="token keyword">public</span> <span class="token variable">$timestamps</span> <span class="token operator">=</span> <span class="token boolean constant">false</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><p>Migrations:</p> <div class="language-php extra-class"><pre class="language-php"><code>Schema<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'categories'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>Blueprint <span class="token variable">$table</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">bigIncrements</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'id'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">string</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'image'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">nullable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">timestamps</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
Schema<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'category_translations'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>Blueprint <span class="token variable">$table</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">bigIncrements</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'id'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">unsignedBigInteger</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'category_id'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">string</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'locale'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">index</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">string</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'name'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">text</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'description'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">nullable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">unique</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'category_id'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'locale'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$table</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">foreign</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'category_id'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">references</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'id'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">on</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'categories'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">onDelete</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'cascade'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">onUpdate</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'cascade'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>Now all you need to do on the CRUD controller is specify translated widgets with <code>translation</code> property.</p> <p>CategoryController.php:</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">class</span> <span class="token class-name">CategoryController</span> <span class="token keyword">extends</span> <span class="token class-name">CrudController</span>
<span class="token punctuation">{</span>
<span class="token keyword">protected</span> <span class="token keyword">static</span> <span class="token keyword">function</span> <span class="token function">properties</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> CrudProperties
<span class="token punctuation">{</span>
<span class="token keyword">return</span> CrudProperties<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'categories'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">title</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Category'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">titles</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Categories'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">model</span><span class="token punctuation">(</span>Category<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">icon</span><span class="token punctuation">(</span>MaterialIcons<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token constant">GROUP_WORK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function">init</span><span class="token punctuation">(</span>string <span class="token variable">$type</span><span class="token punctuation">,</span> Model <span class="token variable">$item</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span><span class="token punctuation">:</span> void
<span class="token punctuation">{</span>
<span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">widgets</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> IdWidget<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">widgets</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> UppyWidget<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">image</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'image'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">widgets</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> TextWidget<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'name'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">rules</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'required'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">translation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// multilingal</span>
<span class="token variable">$this</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">widgets</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> TextAreaWidget<span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'description'</span><span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token operator">></span><span class="token function">translation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// multilingal</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="multilingual-setting"><a href="#multilingual-setting" class="header-anchor">#</a> Multilingual Setting</h2> <p>In setting controllers you don't need to worry about anything.
Just add translation to multilingual properties.</p> <h3 id="access-to-setting-values"><a href="#access-to-setting-values" class="header-anchor">#</a> Access To setting values</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token function">setting</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'group.name'</span><span class="token punctuation">)</span> <span class="token comment">// Just like a normal setting</span>
</code></pre></div><p>Access with specific locale, you should pass locale as the third parameter.</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token function">setting</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'group.name'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'Default Value'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'fa'</span><span class="token punctuation">)</span> <span class="token comment">// سلام</span>
<span class="token function">setting</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'group.name'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'Default Value'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'en'</span><span class="token punctuation">)</span> <span class="token comment">// Hello</span>
</code></pre></div><h3 id="set-settings-programmatically"><a href="#set-settings-programmatically" class="header-anchor">#</a> Set settings programmatically</h3> <p>To set a multilingual setting you should pass locale as the third parameter.</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token function">setting</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'group.name'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'سلام'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'fa'</span><span class="token punctuation">)</span>
<span class="token function">setting</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'group.name'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'Hello'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'en'</span><span class="token punctuation">)</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/sanjabteam/docs/edit/master/docs/localization.md" target="_blank" rel="noopener noreferrer">Help us improve this page!</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/actions.html" class="prev">
Actions
</a></span> <span class="next"><a href="/authorization.html">
Authorization
</a>
→
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/assets/js/app.bb080b10.js" defer></script><script src="/assets/js/3.0ca36dc4.js" defer></script><script src="/assets/js/46.22ab45aa.js" defer></script>
</body>
</html>