How to make Date Range filter Turkish

How to make Date Range filter Turkish

ErenakgzErenakgz Posts: 8Questions: 2Answers: 0

Hi, I am using Date range filter. months are coming in English, can I change the language of this to Turkish?

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    Answer ✓

    Here are the datetime defaults that you can replace:

    i18n: {
            clear:    'Clear',
            previous: 'Previous',
            next:     'Next',
            months:   [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],
            weekdays: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
            amPm:     [ 'am', 'pm' ],
            hours:    'Hour',
            minutes:  'Minute',
            seconds:  'Second',
            unknown:  '-',
            today:    'Today'
    },
    

    Found this for Turkish: https://datatables.net/plug-ins/i18n/Turkish

    I rolled my own version for German but you should be able to easily adapt this for Turkish as well.

    $.extend( true, $.fn.dataTable.Editor.defaults, {            
        i18n: {
            remove: {
                button: "Löschen",
                title:  "Eintrag löschen",
                submit: "Endgültig Löschen",
                confirm: {
                    _: 'Sind Sie sicher, dass Sie die %d ausgewählten Zeilen löschen wollen?',
                    1: 'Sind Sie sicher, dass Sie die ausgewählte Zeile löschen wollen?'
                }
            },
            edit: {
                button: "Bearbeiten",
                title:  "Eintrag bearbeiten",
                submit: "Änderungen speichern"
            },
            create: {
                button: "Neuer Eintrag",
                title:  "Neuen Eintrag anlegen",
                submit: "Neuen Eintrag speichern"
            },
            datetime: {
                    previous: 'Zurück',
                    next:     'Weiter',
                    months:   [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ],
                    weekdays: [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
                    amPm:     [ 'am', 'pm' ],
                    hours:    'Stunde',
                    minutes:  'Minute',
                    seconds:  'Sekunde',
                    unknown:  '-'
            },
            error: {
                    system: "Ein Systemfehler ist aufgetreten (<a target=\"_blank\" href=\"//datatables.net/tn/12\">Für mehr Informationen</a>)."
            },
            multi: {
                    title: "Mehrere Werte",         
                    info: "Die ausgewählten Zeilen enthalten verschiedene Werte für dieses Feld. Um alle Zeilen auf den gleichen Wert zu setzen, \n\
                           klicken Sie bitte hier. Ansonsten werden die Zeilen ihren individuellen Wert für das Feld behalten.",
                    restore: "Änderungen rückgängig machen",
                    noMulti: "Dieses Feld kann einzeln bearbeitet werden, aber nicht als Teil einer Gruppe."
            }
        }      
    });
    
  • ErenakgzErenakgz Posts: 8Questions: 2Answers: 0
    edited April 2022

    It was the first code you threw. Thank you so much.

  • ErenakgzErenakgz Posts: 8Questions: 2Answers: 0

    Now, when I look at it again, when choosing the date, it is in Turkish, and after selecting the date, the text appears in English.

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    edited April 2022

    I think you will need to change your date formatting! That should be independent of the i18n features Data Tables provides.

    I render my dates server side (English UK or German formats) and use date field masking for the respective languages as well.

    Your date is a classic English US date.
    @kthorngren do you have any idea how to change that?

    Roland

    @Erenakgz what is the date format that you want?

    I use moment.js for date formatting and the like

    <!-- Moment.js: -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
    <!-- Locales for moment.js-->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/de.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/en-gb.js"></script>
    

    This one looks like the Turkish locale file (very many ü and ö - like in German :smile: )
    https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/tr.js

    Here I am using the moment locale in an Editor date field definition:

    }, {
                label: lang === 'de' ? 'Datum:' : 'Date:',
                name: "date_field",
                type: "datetime",
                format: 'L',
                opts: {
                    showWeekNumber: true,
                    yearRange: 40,
                    momentLocale: momentLocale
                }
    

    I use format 'L' and the respective moment Locale file (either "de" or "en-gb").

    So you can either also use moment.js or - if the only language you support is Turkish - you just hard code the date format like in here:

    }, {
                label: lang === 'de' ? 'Datum:' : 'Date:',
                name: "date_field",
                type: "datetime",
                format: 'DD.MM.YYYY'
    

    I see that format 'L' in Turkish is the same as in German :smile:

  • ErenakgzErenakgz Posts: 8Questions: 2Answers: 0

    Thank you very much for your help. My country's date format is dd.mm.yyyy

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    edited April 2022 Answer ✓

    My country's date format is dd.mm.yyyy

    I am pretty sure it is case sensitive in Javascript. So rather use 'DD.MM.YYYY'

    You probably didn't have "format" specified initially, right? And that is when the "default" kicks in - and in the world of software that is always English (US) I am afraid.

  • ErenakgzErenakgz Posts: 8Questions: 2Answers: 0

    Finally happened. Thank you for everything.

  • ErenakgzErenakgz Posts: 8Questions: 2Answers: 0
    edited April 2022

    Hello again my friend, When I do it with the date format of my own country, this time it does not list the new date in the table according to the old one. How can I solve this? @rf1234

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    edited April 2022

    No idea! Please post your code and your target date format in the data table.

    I can only tell you how I do it:
    - I do the date rendering on the server: from mysql date format to German or English UK formats and vice versa - depending on user language
    - On the client side I don't do any date rendering: Users see and edit dates in their respective language (German or English UK).

    Many developers however do date rendering client side. They pass the mysql date format back and forth to the server. Either way you have to make sure that
    - date rendering for the data table is being done
    - the date format for Editor is defined.

    Both are independent of each other! You can have completely different date formats in Editor and in your Data Table.

Sign In or Register to comment.