Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JSON_UNESCAPED_UNICODE flag to json_encode #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nalognl
Copy link

@nalognl nalognl commented Nov 21, 2022

It helps to dramatically reduce the generated JavaScript file size

In my testing, I was able to reduce file size from 170kb to 90kb because I had lots of escaped Cyrillic characters.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
It helps to dramatically reduce the generated JavaScript file size

In my testing, I was able to reduce file size from 170kb to 90kb because I had lots of escaped Cyrillic characters.
@SerhiiCho
Copy link

It's a tiny change, can we just accept it?

@rmariuzzo rmariuzzo added this to the 1.11.0 milestone Jun 19, 2023
@Chomiciak
Copy link

What happens if someone's environment is not set to accept files encoded in non-ascii?

@SerhiiCho
Copy link

What happens if someone's environment is not set to accept files encoded in non-ascii?

It can be as a configuration option "unescape_unicode" that defaults to false

@SerhiiCho
Copy link

SerhiiCho commented Feb 19, 2025

It would look like this in the config file:

<?php

return [
    /*
     * Determines whether to use the JSON_UNESCAPED_UNICODE flag when encoding
     * translation files to JSON.  
     * 
     * Setting this to true will prevent Unicode characters from being escaped 
     * (e.g., "你好" instead of "\u4f60\u597d"), which can reduce file size 
     * and improve readability.  
     * 
     * Set to false to escape Unicode characters for compatibility.
     */
    'unescape_unicode' => false,

    /*
     * Set the names of files you want to add to generated javascript.
     * Otherwise all the files will be included.
     *
     * 'messages' => [
     *     'validation',
     *     'forum/thread',
     * ],
     */
    'messages' => [

    ],

    /*
     * The default path to use for the generated javascript.
     */
    'path' => public_path('messages.js'),
];

@SerhiiCho
Copy link

I can make a PR after I get some feedback. This current PR is also mine from the previous company's account nalognl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants