*

morfik

  • ****
  • 169 posts
Translation for jquery
« on: February 19, 2023, 09:38:38 AM »
Since the jquery included in Osclass can't be translated, I was looking for some solution, and it looks like that jquery can be translated.
See the following links:
https://github.com/wikimedia/jquery.i18n
https://github.com/jquery/jquery-ui/tree/main/ui/i18n

The question is how to integrate this with Osclass?


I've found this:
https://stackoverflow.com/questions/494958/how-do-i-localize-the-jquery-ui-datepicker/2905411

But I have no idea what to do with it.
« Last Edit: February 19, 2023, 09:40:15 AM by morfik »

*

MB Themes

Re: Translation for jquery
« Reply #1 on: February 22, 2023, 08:41:24 PM »
This seems to be easiest way:

Code: [Select]
  $.datepicker.setDefaults({
    closeText: "关闭",
    prevText: "<上月",
    nextText: "下月>",
    currentText: "今天",
    monthNames: [ "一月","二月","三月","四月","五月","六月",
    "七月","八月","九月","十月","十一月","十二月" ],
    monthNamesShort: [ "一月","二月","三月","四月","五月","六月",
    "七月","八月","九月","十月","十一月","十二月" ],
    dayNames: [ "星期日","星期一","星期二","星期三","星期四","星期五","星期六" ],
    dayNamesShort: [ "周日","周一","周二","周三","周四","周五","周六" ],
    dayNamesMin: [ "日","一","二","三","四","五","六" ],
    weekHeader: "周",
    dateFormat: "yy-mm-dd",
    firstDay: 1,
    isRTL: false,
    showMonthAfterYear: true,
    yearSuffix: "年"
  });
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #2 on: February 22, 2023, 09:11:39 PM »
I know I could just rewrite all the fields in Polish, but I wanted to have also the English version.

*

MB Themes

Re: Translation for jquery
« Reply #3 on: February 24, 2023, 09:13:21 PM »
@morfik
You might use this code and show whatever you need based on user locale, if you place it i.e. to footer.php.

Example:
Code: [Select]
$.datepicker.setDefaults({
    closeText: "<?php echo osc_esc_html(__('Close''delta')); ?>"
});
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #4 on: February 24, 2023, 09:17:20 PM »
Hmmm, How to make it depend on user locale?

*

MB Themes

Re: Translation for jquery
« Reply #5 on: February 25, 2023, 01:33:05 PM »
@morfik
You might use this code and show whatever you need based on user locale, if you place it i.e. to footer.php.

Example:
Code: [Select]
$.datepicker.setDefaults({
    closeText: "<?php echo osc_esc_html(__('Close''delta')); ?>"
});

Osclass will handle traslations.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #6 on: February 25, 2023, 01:41:33 PM »
OK, I'll try and see how it works.

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #7 on: February 25, 2023, 03:27:30 PM »
OK, I've managed to figure it out only partially.

I added the following at the end of the themes/delta/footer.php file.

Code: [Select]
<script type="text/javascript">
$.datepicker.regional['pl'] = { // Polish regional settings
closeText: '<?php echo osc_esc_js __('Zamknij') ); ?>', // Display text for close link
prevText: '<?php echo osc_esc_js __('Poprzedni') ); ?>', // Display text for previous month link
nextText: '<?php echo osc_esc_js __('Następny') ); ?>', // Display text for next month link
currentText: '<?php echo osc_esc_js __('Dziś') ); ?>', // Display text for current month link
monthNames: ['<?php echo osc_esc_js __('Styczeń') ); ?>','<?php echo osc_esc_js __('Luty') ); ?>','<?php echo osc_esc_js __('Marzec') ); ?>','<?php echo osc_esc_js __('Kwiecień') ); ?>','<?php echo osc_esc_js __('Maj') ); ?>','<?php echo osc_esc_js __('Czerwiec') ); ?>','<?php echo osc_esc_js __('Lipiec') ); ?>','<?php echo osc_esc_js __('Sierpień') ); ?>','<?php echo osc_esc_js __('Wrzesień') ); ?>','<?php echo osc_esc_js __('Październik') ); ?>','<?php echo osc_esc_js __('Listopad') ); ?>','<?php echo osc_esc_js __('Grudzień') ); ?>'], // Names of months for drop-down and formatting
monthNamesShort: ['<?php _e('Sty'); ?>', '<?php _e('Lut'); ?>', '<?php _e('Mar'); ?>', '<?php _e('Kwi'); ?>', '<?php _e('Maj'); ?>', '<?php _e('Cze'); ?>', '<?php _e('Lip'); ?>', '<?php _e('Sie'); ?>', '<?php _e('Wrz'); ?>', '<?php _e('Paź'); ?>', '<?php _e('Lis'); ?>', '<?php _e('Gru'); ?>'], // For formatting
dayNames: ['<?php echo osc_esc_js __('Niedziela') ); ?>', '<?php echo osc_esc_js __('Poniedziałek') ); ?>', '<?php echo osc_esc_js __('Wtorek') ); ?>', '<?php echo osc_esc_js __('Środa') ); ?>', '<?php echo osc_esc_js __('Czwartek') ); ?>', '<?php echo osc_esc_js __('Piątek') ); ?>', '<?php echo osc_esc_js __('Sobota') ); ?>'], // For formatting
dayNamesShort: ['<?php _e('Nie'); ?>', '<?php _e('Pon'); ?>', '<?php _e('Wto'); ?>', '<?php _e('Śro'); ?>', '<?php _e('Czw'); ?>', '<?php _e('Pią'); ?>', '<?php _e('Sob'); ?>'], // For formatting
dayNamesMin: ['<?php _e('Ni'); ?>','<?php _e('Po'); ?>','<?php _e('Wt'); ?>','<?php _e('Śr'); ?>','<?php _e('Cz'); ?>','<?php _e('Pi'); ?>','<?php _e('So'); ?>'], // Column headings for days starting at Sunday
weekHeader: '<?php _e('Tydz'); ?>', // Column header for week of the year
dateFormat: 'dd.mm.yy', // See format options on parseDate
firstDay: 1, // The first day of the week, Sun = 0, Mon = 1, ...
isRTL: false, // True if right-to-left language, false if left-to-right
showMonthAfterYear: false, // True if the year select precedes month, false for month then year
yearSuffix: '' // Additional text to append to the year in the month headers
};
$.datepicker.setDefaults($.datepicker.regional['pl']);
</script>

And I see the Polish names now. But when I switch to English, I still see the Polish names. So it looks like it doesn't follow locales.

*

MB Themes

Re: Translation for jquery
« Reply #8 on: February 25, 2023, 05:25:19 PM »
You have added static "pl" code here
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #9 on: February 25, 2023, 06:21:03 PM »
So what should it look like?

I tried custom, but it also didn't work.

*

MB Themes

Re: Translation for jquery
« Reply #10 on: March 07, 2023, 01:34:33 PM »
@morfik
Translations are done in PO files, not in code!

Code: [Select]
<script type="text/javascript">
$.datepicker.regional['<?php echo osc_current_user_locale(); ?>'] = {
closeText: '<?php echo osc_esc_js (__('Close')); ?>'
}

You update PO files from source and translate it.
If you are adding this in plugin, that translation function looks like:
Code: [Select]
__('Close', 'plugin_folder_name')
.. same for theme.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #11 on: March 07, 2023, 01:53:22 PM »
I'm not sure whether I follow.

There's a file called:  osclass/oc-includes/osclass/frm/Field.form.class.php . In this file there's the following code:

Code: [Select]
/**
 * Class FieldForm
 */
class FieldForm extends Form {
  public static function i18n_datePicker() {
    ?>
    <script type="text/javascript">
      $.datepicker.regional['custom'] = { // Default regional settings
....

So maybe this is the place to make all this work?

*

MB Themes

Re: Translation for jquery
« Reply #12 on: March 08, 2023, 12:49:43 PM »
Well you should most probably just test in your theme.
Do not think it must come together with original script.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

morfik

  • ****
  • 169 posts
Re: Translation for jquery
« Reply #13 on: March 08, 2023, 01:21:04 PM »
I just wanted to translate the untranslated words. It looks like that $.datepicker.regional exists in the osclass and it is already prepared for translation. The question is, why it doesn't work, i.e it presents the date picker windows to the user with English words/phrases no matter what language is set?

*

MB Themes

Re: Translation for jquery
« Reply #14 on: March 09, 2023, 11:53:42 AM »
@morfik
I think reason is that it's used by how many, 1-2 people? And nowadays everyone knows what's Monday.
So it's considered as very low priority and always was.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots