{"id":3960,"date":"2023-09-22T07:39:02","date_gmt":"2023-09-22T06:39:02","guid":{"rendered":"https:\/\/help.expertsender.com\/?post_type=es&#038;p=3960"},"modified":"2024-03-19T13:25:45","modified_gmt":"2024-03-19T12:25:45","slug":"get-text","status":"publish","type":"es","link":"https:\/\/help.expertsender.com\/pl\/emp\/dynamic-content\/text-operations\/get-text\/","title":{"rendered":"Get text"},"content":{"rendered":"\n<p>Dynamic Content can be used to get localized text based on subscriber locale, using GetText method.<\/p>\n\n\n\n<p>To use this you need to create data table with name Translations and following structure:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Column name<\/th><th>Type<\/th><th>PK<\/th><\/tr><\/thead><tbody><tr><td>key<\/td><td>string(255)<\/td><td>Yes<\/td><\/tr><tr><td>locale<\/td><td>string min. 7 characters<\/td><td>Yes<\/td><\/tr><tr><td>translation<\/td><td>text<\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Method signature:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:8.4375px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"${GetText(key, locale, fallback, valuepairs)}\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">$<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">GetText<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\">key<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> locale<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> fallback<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> valuepairs<\/span><span style=\"color: #89DDFF\">)}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>key<\/code> of translated value<\/li>\n\n\n\n<li><code>locale<\/code> is a culture of translation e.g. &#8216;RU&#8217;, &#8216;PL&#8217;, &#8216;default&#8217;<\/li>\n\n\n\n<li><code>fallback<\/code> is default value which will be returned when there is no translation for provided key and locale and there is no default locale for the key.<\/li>\n\n\n\n<li><code>valuepairs<\/code> is dictionary of parameters which will be replaced in translated sentence. Note that parameter name needs to be placed between % signs.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Let&#8217;s say that we have following rows in our Translations table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Key<\/th><th>Locale<\/th><th>translation<\/th><\/tr><\/thead><tbody><tr><td>expiration_date<\/td><td>default<\/td><td>Your %param_account% subscription expires on: %param_date%<\/td><\/tr><tr><td>expiration_date<\/td><td>PL<\/td><td>Twoja subskrypcja %param_account% wygasa: %param_date%<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:16.859375px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"&lt;%\nvar valuepairs = new System.Collections.Generic.Dictionary&lt;string, string&gt;();\n\nvaluepairs.Add('param_account','Netflix');\nvaluepairs.Add('param_date','2020-04-15 00:13:00');\n%&gt;\n\nDefault: ${GetText('expiration_date')} &lt;br \/&gt;\nDefault: ${GetText('expiration_date', 'default', '', valuepairs)} &lt;br \/&gt;\n\nPL: ${GetText('expiration_date', 'PL', '', valuepairs)} &lt;br \/&gt;\n\nBR (no translation in table): ${GetText('expiration_date', 'BR', '', valuepairs)} &lt;br \/&gt;\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #89DDFF\">&lt;%<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">var<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #FFCB6B\">valuepairs<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">new<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #FFCB6B\">System<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #FFCB6B\">Collections<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #FFCB6B\">Generic<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #FFCB6B\">Dictionary<\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #89DDFF\">string<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">string<\/span><span style=\"color: #89DDFF\">&gt;();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">valuepairs<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">Add<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">param_account<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Netflix<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">valuepairs<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">Add<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">param_date<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2020-04-15 00:13:00<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">%&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">Default<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #BABED8\"> $<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">GetText<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">expiration_date<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">)}<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #BABED8\">br <\/span><span style=\"color: #89DDFF\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">Default<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #BABED8\"> $<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">GetText<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">expiration_date<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">default<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> valuepairs<\/span><span style=\"color: #89DDFF\">)}<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #BABED8\">br <\/span><span style=\"color: #89DDFF\">\/&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">PL<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #BABED8\"> $<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">GetText<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">expiration_date<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">PL<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> valuepairs<\/span><span style=\"color: #89DDFF\">)}<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #BABED8\">br <\/span><span style=\"color: #89DDFF\">\/&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #82AAFF\">BR<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #BABED8\">no translation <\/span><span style=\"color: #C792EA\">in<\/span><span style=\"color: #BABED8\"> table<\/span><span style=\"color: #89DDFF\">):<\/span><span style=\"color: #BABED8\"> $<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">GetText<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">expiration_date<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">BR<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> valuepairs<\/span><span style=\"color: #89DDFF\">)}<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #BABED8\">br <\/span><span style=\"color: #89DDFF\">\/&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Output:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:8.4375px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"Default: Your %param_account% subscription expires on: %param_date%\nDefault: Your Netflix subscription expires on: 2020-04-15 00:13:00\nPL: Twoja subskrypcja Netflix wygasa: 2020-04-15 00:13:00\nBR (no translation in table): Your Netflix subscription expires on: 2020-04-15 00:13:00\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">Default: Your %param_account% subscription expires on: %param_date%<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">Default: Your Netflix subscription expires on: 2020-04-15 00:13:00<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">PL: Twoja subskrypcja Netflix wygasa: 2020-04-15 00:13:00<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">BR (no translation in table): Your Netflix subscription expires on: 2020-04-15 00:13:00<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"author":5,"featured_media":0,"parent":3952,"menu_order":187,"template":"","format":"standard","emp-category":[],"class_list":["post-3960","es","type-es","status-publish","format-standard","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es"}],"about":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/types\/es"}],"author":[{"embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/users\/5"}],"version-history":[{"count":2,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3960\/revisions"}],"predecessor-version":[{"id":8901,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3960\/revisions\/8901"}],"up":[{"embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3952"}],"wp:attachment":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/media?parent=3960"}],"wp:term":[{"taxonomy":"emp-category","embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/emp-category?post=3960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}