RGMSSONI / localizedproperties

Automatically exported from code.google.com/p/localizedproperties
0 stars 0 forks source link

UTF-8 support #96

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello?
I live in Korea, DK Lee is known as a developer.
'Localizedproperties' is always used to appreciate.

I hope to add in one kind of ability to do so, try to create issues.

South Korea and Japan, countries like China are using the 2byte(UTF-8) 
characters.
By default, properties file encoded in ISO-8859-1 because
"로그인" when the writing '\ub85c\uadf8\uc778'is taken to be the same type.
So far we have used this utility to 
http://propedit.sourceforge.jp/index_en.html.
The utility of the Japanese people had to go through the same problem with me 
is an open source plug-made.

However, do not support the editing capabilities of cellular properties, but 
merely Santorini multilingual utility that converts files only for editing the 
file had been difficult.

So I 'localizedproperties' unusual ... and simply make some changes that could 
solve the problem.

1.
Property [] com.triadsoft.properties.model.ResourcesBag.getProperties ()
In the
property.setValue (defaultLocale, EncodeChanger.unicodeEsc2Unicode 
(defaultEntry.getValue ()));
With
property.setValue (loc, EncodeChanger.unicodeEsc2Unicode (entry.getValue ()));

    public Property[] getProperties() {
        ArrayList<Property> list = new ArrayList<Property>();
        PropertyFile defaultProperties = get(defaultLocale);
        for (Iterator<String> iter = allKeys.iterator(); iter.hasNext();) {
            String key = (String) iter.next();
            Property property = new Property(key);
            // Si no encuentra la entrada en el archivo por default
            // agrega la clave al archivo
            PropertyEntry defaultEntry = defaultProperties
                    .getPropertyEntry(key);
            if (defaultEntry == null) {
                defaultEntry = new PropertyEntry(null, key, null);
                defaultProperties.getDefaultCategory().addEntry(defaultEntry);
            }
            property.setValue(defaultLocale, EncodeChanger.unicodeEsc2Unicode(defaultEntry.getValue()));

            for (Iterator<Locale> itera = keySet().iterator(); itera.hasNext();) {
                Locale loc = itera.next();
                if (defaultLocale.equals(loc)) {
                    continue;
                }
                PropertyFile properties = ((PropertyFile) get(loc));
                PropertyEntry entry = properties.getPropertyEntry(key);
                if (entry == null) {
                    entry = new PropertyEntry(null, key, null);
                    properties.getDefaultCategory().addEntry(entry);
                }
                property.setValue(loc, EncodeChanger.unicodeEsc2Unicode(entry.getValue()));
            }
            list.add(property);
        }
        return list.toArray(new Property[list.size()]);
    }

2.
boolean com.triadsoft.properties.model.ResourcesBag.changeValue (Locale locale, 
String key, String oldValue, String newValue)
In the
pe.setValue (EncodeChanger.unicode2UnicodeEsc (newValue));

    public boolean changeValue(Locale locale, String key, String oldValue,
            String newValue) {
        boolean hasChanged = false;
        if (locale == null || !containsKey(locale)) {
            throw new RuntimeException("El locale no es valido");
        }
        if (newValue != null && !newValue.equals(oldValue)) {
            IPropertyFile pf = get(locale);
            PropertyEntry pe = pf.getPropertyEntry(key);
            pe.setValue(EncodeChanger.unicode2UnicodeEsc(newValue));

            // try {
            // pf.getFile().getParent().refreshLocal(IFile.DEPTH_ONE, null);
            // } catch (CoreException e) {
            // LocalizedPropertiesLog.error(e.getMessage(), e);
            // }
            hasChanged = true;
        }
        return hasChanged;
    }

3. And I've added utility.
This utility will be brought in http://propedit.sourceforge.jp/index_en.html 
source.

package com.triadsoft.properties.model.utils;

/*****************************************************
 *
 *   @author  Sou Miyazaki
 *
 ****************************************************/

/**
 * <pre>
 * edit by byuri
 * </pre>
 * 
 * @author Sou Miyazaki
 * @author byuri
 * @since  ?
 * @version 2012. 1. 17. byuri : edit
 *
 */
public class EncodeChanger
{
    public static final int LOWERCASE = 0;
    public static final int UPPERCASE = 1;

    /**
     * 
     * @param UniStr
     * @since 1.0.0
     */
    public static String unicode2UnicodeEsc(String uniStr)
    {
        return EncodeChanger.unicode2UnicodeEsc(uniStr, LOWERCASE);
    }

    /**
     * 
     * @param UniStr
     * @param charcase
     */
    public static String unicode2UnicodeEsc(String uniStr, int charcase)
    {
        StringBuffer ret = new StringBuffer();
        if (uniStr == null)
        {
            return null;
        }
        int maxLoop = uniStr.length();
        for (int i = 0; i < maxLoop; i++)
        {
            char character = uniStr.charAt(i);
            if (character <= 127)
            {
                ret.append(character);
            }
            else
            {
                ret.append("\\u"); //$NON-NLS-1$
                String hexStr = null;
                if (charcase == UPPERCASE)
                {
                    hexStr = Integer.toHexString(character).toUpperCase();
                }
                else
                {
                    hexStr = Integer.toHexString(character).toLowerCase();
                }
                int zeroCount = 4 - hexStr.length();
                for (int j = 0; j < zeroCount; j++)
                {
                    ret.append('0');
                }
                ret.append(hexStr);
            }
        }
        return ret.toString();
    }

    /**
     * 
     * @param EscStr
     * @since 1.0.0
     */
    public static String unicodeEsc2Unicode(String unicodeStr)
    {
        if (unicodeStr == null)
        {
            return null;
        }

        StringBuffer retBuf = new StringBuffer();
        int maxLoop = unicodeStr.length();
        for (int i = 0; i < maxLoop; i++)
        {
            if (unicodeStr.charAt(i) == '\\')
            {
                if (i < maxLoop - 5 && (unicodeStr.charAt(i + 1) == 'u' || unicodeStr.charAt(i + 1) == 'U'))
                {
                    try
                    {
                        retBuf.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));
                        i += 5;
                    }
                    catch (NumberFormatException e)
                    {
                        retBuf.append(unicodeStr.charAt(i));
                    }
                }
                else
                {
                    retBuf.append(unicodeStr.charAt(i));
                }
            }
            else
            {
                retBuf.append(unicodeStr.charAt(i));
            }
        }
        return retBuf.toString();
    }
}

I already modified by the need to use.
If you do not mind, I hope the next version update will refer to when.
2byte(UTF-8) character support for people like me can be a really useful 
feature.

My English is not enough, please understand that Google was translated into 
points.

Disclose to the open source plug-in, Thank you.
Happy New Year.

Original issue reported on code.google.com by mill...@gmail.com on 18 Jan 2012 at 3:07

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi!
I'm DK Lee, live in Korea, a developer.
'Localizedproperties' are always used and appreciated.

I hope to add in one kind of function to do so,  this will create issues.

Google translate was weird ... 

Original comment by mill...@gmail.com on 18 Jan 2012 at 4:33

GoogleCodeExporter commented 8 years ago
Google translate was weird ... 

Delete this please?
If you can not delete please close.

I'll regenerate.

Original comment by mill...@gmail.com on 18 Jan 2012 at 4:37

GoogleCodeExporter commented 8 years ago
Thank you, your comments and code are welcomed.
I'm not english speaker (my first language is spanish), but I understood 
perfectly well your intentions, and thanks you for share your code.
Please, could you provide me a property file with UTF-8 codes, to test your 
code.
Again, thank you for your time.

Original comment by flores.l...@gmail.com on 18 Jan 2012 at 7:16

GoogleCodeExporter commented 8 years ago
I think that this issue has been solved, because I tested plugin with example 
files I received by another user.
One of them was a Russian and other was Korean.
Please, could you test it with next version 0.8.5? Thank you

Original comment by flores.l...@gmail.com on 4 Nov 2012 at 1:26

GoogleCodeExporter commented 8 years ago

Original comment by flores.l...@gmail.com on 4 Nov 2012 at 9:21