{"id":4098,"date":"2019-03-24T18:02:34","date_gmt":"2019-03-24T18:02:34","guid":{"rendered":"https:\/\/help.perfexcrm.com\/?p=4098"},"modified":"2025-10-16T11:18:18","modified_gmt":"2025-10-16T11:18:18","slug":"module-language","status":"publish","type":"post","link":"https:\/\/help.perfexcrm.com\/module-language\/","title":{"rendered":"Module Language"},"content":{"rendered":"\n<p>Each module can have separate language files to prevent messing up with the <a href=\"https:\/\/help.perfexcrm.com\/system-language\/\">system language<\/a> files. <\/p>\n\n\n\n<p>To add language files to your module so users can translate it, you must create a folder in <strong>modules\/<\/strong>[module_name]<strong>\/language\/<\/strong>[language_name_folder]<\/p>\n\n\n\n<p><strong>At this time the [language_name_folder] must exist in the core language files located in application\/language<\/strong>\ufeff<br><\/p>\n\n\n\n<p>For example, if you want to create English language translations, you will create the following folder(s): <strong>\/modules\/[module_name]\/language\/<g class=\"gr_ gr_3 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace\" id=\"3\" data-gr-id=\"3\">english<\/g><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Language Files<\/h3>\n\n\n\n<p>In each language, you can create unlimited number of files e.q. if you want to separate specific features language files or you can include them in one general language file.<\/p>\n\n\n\n<p>The <strong>file name must end with _lang.php<\/strong>, you should check the Codeigniter framework <a href=\"https:\/\/www.codeigniter.com\/userguide3\/libraries\/language.html\">documentation <\/a>for more info about the language file name and it&#8217;s usage.<\/p>\n\n\n\n<p>In this example we will create <strong>sample_module_lang.php<\/strong> file in \/modules\/<strong>[module_name]<\/strong>\/language\/english\/<\/p>\n\n\n\n<p>For each additional language you want to have translations, you must include all files from your general language e.q. in this case English<\/p>\n\n\n\n<p>For example, if you have 3 language files in the \/<g class=\"gr_ gr_3 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"3\" data-gr-id=\"3\">english<\/g> folder and you want to include new Spanish language, you must create new folder for the Spanish language and copy those 3 language files in the \/<g class=\"gr_ gr_4 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"4\" data-gr-id=\"4\">spanish<\/g> folder.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Registering Language Files<\/h3>\n\n\n\n<p>Instead of loading the language files directly there is a helper function to register the language files and allow your language to support using<strong> <\/strong> a<strong> custom_lang.php<\/strong> file so the end users can overwrite the translations.<\/p>\n\n\n\n<p>More info about custom_lang.php file in the language directory can be found <a href=\"https:\/\/help.perfexcrm.com\/overwrite-translation-text\/\">here<\/a><\/p>\n\n\n\n<p>In your <strong>module init file<\/strong> add the following code:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" 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-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>register_language_files('module_name', &#91;'sample_module'&#93;);<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/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=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">register_language_files<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">module_name<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #ECEFF4\">&#91;<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">sample_module<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #ECEFF4\">&#93;)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The first parameter to the <strong>register_language_files <\/strong>function is the module name, don&#8217;t forget to replace <strong>module_name <\/strong>with your actual module name.<\/p>\n\n\n\n<p>The second parameter must be an array with language files names <strong>without the _lang.php.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Fetching a Line of Text<\/h3>\n\n\n\n<p>Instead of using the Codeigniter framework default method to fetch translation line of text, you can use Perfex CRM custom function:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" 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;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/**\n * @param  string $line   language line key\n * @param  mixed $label   label e.q. if you have $lang&#91;'sample_module_create_new'&#93; = 'Create New %s';\n * @return string         language text\n *\/\n_l($line, $label = '', $log_errors = true);<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/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=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #616E88\">\/**<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"> * <\/span><span style=\"color: #81A1C1\">@param<\/span><span style=\"color: #616E88\">  <\/span><span style=\"color: #81A1C1\">string<\/span><span style=\"color: #616E88\"> $line   language line key<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"> * <\/span><span style=\"color: #81A1C1\">@param<\/span><span style=\"color: #616E88\">  <\/span><span style=\"color: #81A1C1\">mixed<\/span><span style=\"color: #616E88\"> $label   label e.q. if you have $lang&#91;&#39;sample_module_create_new&#39;&#93; = &#39;Create New %s&#39;;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"> * <\/span><span style=\"color: #81A1C1\">@return<\/span><span style=\"color: #616E88\"> <\/span><span style=\"color: #81A1C1\">string<\/span><span style=\"color: #616E88\">         language text<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"> *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">_l<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #81A1C1\">$<\/span><span style=\"color: #D8DEE9\">line<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #81A1C1\">$<\/span><span style=\"color: #D8DEE9\">label<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #ECEFF4\">&#39;&#39;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #81A1C1\">$<\/span><span style=\"color: #D8DEE9\">log_errors<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #88C0D0\"> <\/span><span style=\"color: #81A1C1\">true<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Conflicts<\/h3>\n\n\n\n<p>Make sure that your language keys you add in the language files do not conflict with Perfex CRM language keys that are added in <strong>application\/language<\/strong> or with any other modules.<\/p>\n\n\n\n<p><strong>For this reason, we recommend to add unique language keys or prefix them with your module name.<\/strong><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Each module can have separate language files to prevent messing up with the system language files. To add language files to your module so users can translate it, you must create a folder in modules\/[module_name]\/language\/[language_name_folder] At this time the [language_name_folder] must exist in the core language files located in application\/language\ufeff For example, if you want [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-4098","post","type-post","status-publish","format-standard","hentry","category-modules"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/posts\/4098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/comments?post=4098"}],"version-history":[{"count":0,"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/posts\/4098\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/media?parent=4098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/categories?post=4098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.perfexcrm.com\/wp-json\/wp\/v2\/tags?post=4098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}