5

में @ मैसेज एनोटेशन को स्थानांतरित करने के लिए कैसे करें मैं अपने आवेदन में स्थानीयकरण को सरल बनाने के लिए नेटबीन में @Messages एनोटेशन का उपयोग करना चाहता हूं। हालांकि, मुझे इस तंत्र का उपयोग करके अन्य भाषाओं के लिए अनुवाद (बंडल) जोड़ने के बारे में कोई जानकारी नहीं मिल रही है। @Messages का उपयोग कर एक कार्रवाई कीNetBeans

उदाहरण के रूप में इस प्रकार है

@ActionID(category = "category", 
id = "AddAction") 
@ActionRegistration(iconBase = "actions/action-icon.png", 
displayName = "#CTL_AddAction") 
@ActionReferences({ 
    @ActionReference(path = "Menu/Shapes", position = 160), 
    @ActionReference(path = "Toolbars/Shapes", position = 5133) 
}) 
@Messages("CTL_AddAction=Add Action") 

मैं कैसे कार्रवाई जोड़ें भाषा के आधार पर भिन्न करने के लिए मिल सकता है?

उत्तर

6

http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/NbBundle.Messages.html

@Messages एनोटेशन एक Bundle.java वर्ग और एक Bundle.properties फाइल उत्पन्न करेगा। Bundle.java क्लास में स्थानीयकरण के लिए फ़ंक्शंस शामिल होंगे, और Bundle.properties फ़ाइल में कुंजी-मान जोड़े होते हैं जो रूट लोकेल के लिए सटीक स्ट्रिंग निर्धारित करते हैं।

ठीक से स्थानीयकरण के लिए, आपको Bundle.properties फ़ाइल की जांच करनी चाहिए, और उसके बाद Bundle_fr.properties फ़ाइल (फ़्रेंच के लिए) या Bundle_whatever.properties फ़ाइल बनाएं जहां 'जो भी लोकल आप जोड़ना चाहते हैं।

तब, जब वातावरण आपके आवेदन के लिए निर्धारित है, Bundle.java क्लास का उपयोग सही Bundle_xx.properties Bundle.java वर्ग कार्यों के लिए अपने कॉल स्थानीय बनाना दर्ज करनी चाहिए।

package com.testmodule; 

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import org.openide.awt.ActionID; 
import org.openide.awt.ActionReference; 
import org.openide.awt.ActionReferences; 
import org.openide.awt.ActionRegistration; 
import org.openide.util.NbBundle.Messages; 

@ActionID(category = "category", 
id = "com.testmodule.AddAction") 
@ActionRegistration(iconBase = "com/testmodule/action-icon.png", 
displayName = "#CTL_AddAction") 
@ActionReferences({ 
    @ActionReference(path = "Menu/Shapes", position = 160), 
    @ActionReference(path = "Toolbars/Shapes", position = 5133) 
}) 
@Messages({ 
    "CTL_AddAction=Add Action" 
}) 
public final class AddAction implements ActionListener { 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     Locale.setDefault(Locale.FRENCH); 
     System.out.println("I am action "+Bundle.CTL_AddAction()); 
    } 
} 

मेरे बंडल देखो की तरह:

Bundle.properties 
    OpenIDE-Module-Name=testmodule 
Bundle_fr.properties 
    OpenIDE-Module-Name=french testmodule 
    CTL_AddAction=Ajouter une action 
+0

Bundle.properties मौजूद है। इसमें अन्य i18n ग्रंथ भी हैं। मैंने एक स्थानीय गुण फ़ाइल जोड़ दी है, हालांकि उठाया गया पाठ डिफ़ॉल्ट भाषा है, भले ही अन्य ग्रंथ जो एनबीबुंडल का उपयोग करते हैं, सही लोकेल टेक्स्ट उठाते हैं। क्या आपके पास एक कामकाजी उदाहरण होगा जिसके साथ मैं तुलना कर सकता हूं? – Nasir

+0

बस यह सुनिश्चित कर रहा है ... क्या आप अपनी स्थानीय स्ट्रिंग प्राप्त करने के लिए Bundle.java एक्सेसर्स का उपयोग कर रहे हैं? यह Bundle.CTL_AddAction() पर एक उदाहरण पर काम करेगा ... – naugler

+0

मैं जिस कोड को प्रतिस्थापित करना चाहता हूं वह है @Messages ({ "CTL_AddAction = कार्रवाई जोड़ें" })। मैं उम्मीद करता हूं कि "एक्शन एक्शन" स्वचालित रूप से लोकेल संस्करण द्वारा प्रतिस्थापित किया जाएगा, लेकिन ऐसा नहीं है। तो या तो मैं जादू को समझ नहीं पा रहा हूं, या मैं इसे ठीक से नहीं कर रहा हूं। मेरे पास Bundle_fr.properties में एक स्थानीयकृत टेक्स्ट है लेकिन इसे उठाया नहीं जाता है। मुझे नहीं पता कि एनोटेशन का उपयोग करके संदेश कैसे निर्दिष्ट करें। शायद, कुछ स्पष्ट है जो मुझे याद आ रही है ... – Nasir