Package de.timefinder.core.ui

Source Code of de.timefinder.core.ui.CheckI18N

/*
*  Copyright 2009 Peter Karich, peat_hal 'at' users 'dot' sourceforge 'dot' net.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/
package de.timefinder.core.ui;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import javolution.util.FastSet;

/**
* This method reads the english message file and compares which key are missing
*
* @author Peter Karich, peat_hal 'at' users 'dot' sourceforge 'dot' net
*/
public class CheckI18N {

    public static void main(String[] args) throws IOException {
        new CheckI18N().start();
    }

    public void start() throws IOException {
        Properties english = new Properties();
        english.load(getClass().getResourceAsStream("messages.properties"));

        Properties de = new Properties();
        de.load(getClass().getResourceAsStream("messages_de.properties"));


//        Map<String, String> englishMap = FastMap.newInstance();
        Set<String> deKeys = FastSet.newInstance();
        Map<String, String> missingInDE = new TreeMap();
        Set<String> unusedInDE = FastSet.newInstance();

        for (Entry<Object, Object> entry : de.entrySet()) {
            deKeys.add(entry.getKey().toString());
        }

        for (Entry<Object, Object> entry : english.entrySet()) {
            if (!deKeys.contains(entry.getKey().toString()))
                missingInDE.put(entry.getKey().toString(), entry.getValue().toString());
        }

        for (String deKey : deKeys) {
            if (english.get(deKey) == null)
                unusedInDE.add(deKey);
        }

        System.out.println("en:" + english.size());

        System.out.println("de:" + deKeys.size());
        System.out.println("missing in de:" + missingInDE.size());
        System.out.println("unused in de:" + unusedInDE.size());

        System.out.println("\n\n==================\nmissing in de:\n");
        outAsProperties(missingInDE);

        System.out.println("\n\n==================\nunused in de:\n");
        for (String str : unusedInDE) {
            System.out.println(str);
        }
    }

    public void outAsProperties(Map<String, String> map) {
        for (Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }
}
TOP

Related Classes of de.timefinder.core.ui.CheckI18N

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.