4 votes

What programming/technical projects have you been working on?

This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

1 comment

  1. xk3
    (edited )
    Link
    I added support for other eBay marketplaces in my disk prices program: Austria, Australia, Belgium, Canada, Switzerland, Germany, Spain, France, Great Britain, Hong Kong, Ireland, Italy,...

    I added support for other eBay marketplaces in my disk prices program: Austria, Australia, Belgium, Canada, Switzerland, Germany, Spain, France, Great Britain, Hong Kong, Ireland, Italy, Netherlands, Poland, Singapore, United States. Typing out this message made me realize there was a bug in my link extracting function that I use everywhere so I fixed that (unrelated to the website).

    I've added a lot of small features and bugfixes to the site over the past week. One of the most interesting parts is probably the way that I represent currencies in the different region pages. At first I was customizing everything with a special DataTable render function which required me to pass in data about the way that each currency should be formatted--not just the currency symbol but also the different way that Belgium writes the before the amount and France writes it after--though both use , instead of .. And the Swiss use ' to separate groups of thousands instead of , but . for cents.

    $.fn.dataTable.render.number(',', '.', 2, '$')
    

    All of that information starts to become a bit tedious... but I was making good progress and almost done when I realized that the browser really does a better job at this:

    Enter Intl.NumberFormat!

    I basically replaced all of that complicated code with this:

    const _fmt_currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format
    
    function fmt_currency(data, type, row) {
        if (type === 'display') {
            return _fmt_currency(data);
        }
        return data;
    }
    

    By replacing the currency code for the different pages, it all works inside the browser. A lot easier and more accurate.

    Another thing that I realized that I could do to make things more localized is that instead of doing this (for the number of seller reviews, which is often in the thousands):

    $.fn.dataTable.render.number(',') 
    

    With DataTables.js I can just leave the preset blank and it uses the browser's locale:

    $.fn.dataTable.render.number()
    

    To test this I opened a browser like this:

    LANGUAGE=fr chromium-browser
    

    Neat!