फ़ुलफ़िलमेंट (Dialogflow)
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
आपका फ़ुलफ़िलमेंट लॉजिक, सिस्टम के हर अनुरोध में मिलने वाली स्थानीय स्ट्रिंग का इस्तेमाल कर सकता है
उपयोगकर्ताओं को जवाब दे सकता है. इस गाइड में, तीसरे पक्ष की सेवाओं के इस्तेमाल का तरीका बताया गया है
Firebase के लिए Cloud Function में, स्थानीय भाषा के अनुसार लाइब्रेरी
स्थानीय जगह के हिसाब से जवाब देना.
स्थानीय भाषा के अनुसार लाइब्रेरी
यहां कुछ लाइब्रेरी दी गई हैं जो आपकी मदद कर सकती हैं
विशिष्ट स्थान-भाषाओं के लिए कस्टमाइज़्ड रिस्पॉन्स जनरेट करें:
- सामान्य मकसद: I18n-node (हमारा
उदाहरण के लिए कोड स्निपेट इस लाइब्रेरी का उपयोग करते हैं)
- सामान्य मकसद: format.js
- टाइमज़ोन/टाइम लोकलाइज़ेशन: moment.js (हमारा
उदाहरण के लिए कोड स्निपेट इस लाइब्रेरी का उपयोग करते हैं)
- पैसा/मुद्रा: numeral.js
स्थानीय भाषा में जवाब बनाएं
इस सेक्शन में, स्थानीय भाषा में ऐसी स्ट्रिंग रिसॉर्स फ़ाइलें बनाने का तरीका बताया गया है जो
स्थानीय जगह के अनुसार स्ट्रिंग शामिल होती हैं और इन संसाधन फ़ाइलों को अपने क्लाउड में इस्तेमाल करने का तरीका बताती हैं
Firebase फ़ुलफ़िलमेंट के लिए फ़ंक्शन.
स्थानीय भाषा में जवाब देने के लिए:
- जिस डायरेक्ट्री में आपकी
package.json
और index.js
फ़ाइलें हैं उसी में फ़ाइलें बनाएं
आपकी स्थानीय जगह के मुताबिक स्ट्रिंग फ़ाइलों के लिए locales
डायरेक्ट्री. हम इसके बारे में
<project-dir>/functions/locales
के तौर पर डायरेक्ट्री.
एक ऐसी संसाधन फ़ाइल बनाएं जिसमें हर स्थान-भाषा के लिए स्थानीय जगह के अनुसार स्ट्रिंग शामिल हों
आपको मदद चाहिए. उदाहरण के लिए, अगर आपको en-US
, en-GB
,
और de-DE
स्थान-भाषाएँ, जिनमें स्थानीय जगह के अनुसार स्वागत है और तारीख़ के मैसेज हैं, वे फ़ाइलें
ऐसा दिख सकता है:
<project-dir>/functions/locales/en-US.json
{
"WELCOME_BASIC": "Hello, welcome!",
"DATE": "The date is %s"
}
<project-dir>/functions/locales/en-GB.json
{
"WELCOME_BASIC": "Hello, welcome!",
"DATE": "The date is %s"
}
<project-dir>/functions/locales/de-DE.json
{
"WELCOME_BASIC": "Hallo und willkommen!",
"DATE": "Das Datum ist %s"
}
package.json
फ़ाइल में, i18n-नोड और मोमेंट लाइब्रेरी का एलान इस तरह करें
डिपेंडेंसी:
{
...
"dependencies": {
"actions-on-google": "^2.7.0",
"firebase-admin": "^7.2.1",
"firebase-functions": "^2.2.1",
"i18n": "^0.8.3",
"moment": "^2.22.1"
}
}
index.js
फ़ाइल में, i18n-नोड और मोमेंट के लिए डिपेंडेंसी का एलान करें
लाइब्रेरी:
const i18n = require('i18n');
const moment = require('moment');
index.js
फ़ाइल में, i18n-नोड को उन स्थान-भाषाओं के साथ कॉन्फ़िगर करें जो इसके साथ काम करती हैं:
i18n.configure({
locales: ['en-US', 'en-GB', 'de-DE'],
directory: __dirname + '/locales',
defaultLocale: 'en-US'
});
क्लाइंट लाइब्रेरी से conv.user.locale
का इस्तेमाल करके, लाइब्रेरी के लिए स्थान-भाषा सेट करें
प्रॉपर्टी.
app.middleware((conv) => {
i18n.setLocale(conv.user.locale);
moment.locale(conv.user.locale);
});
स्थानीय जगह के अनुसार जवाब देने के लिए, स्थानीय भाषा वाली स्ट्रिंग के साथ ask()
पर कॉल करें
i18n के ज़रिए वापस किया गया. इस स्निपेट में एक ऐसा फ़ंक्शन भी है जो मोमेंट का इस्तेमाल करता है
स्थानीय जगह के हिसाब से दी गई तारीख दिखाने के लिए:
app.intent('Default Welcome Intent', (conv) => { // must not be async for i18n
conv.ask(i18n.__('WELCOME_BASIC'));
});
app.intent('date', (conv) => { // must not be async for i18n
conv.ask(i18n.__('DATE', moment().format('LL')));
});
उदाहरण के लिए, यहां एक पूरा index.js फ़ाइल दी गई है:
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const i18n = require('i18n');
const moment = require('moment');
i18n.configure({
locales: ['en-US', 'en-GB', 'de-DE'],
directory: __dirname + '/locales',
defaultLocale: 'en-US'
});
const app = dialogflow({debug: true});
app.middleware((conv) => {
i18n.setLocale(conv.user.locale);
moment.locale(conv.user.locale);
});
app.intent('Default Welcome Intent', (conv) => { // must not be async for i18n
conv.ask(i18n.__('WELCOME_BASIC'));
});
app.intent('date', (conv) => { // must not be async for i18n
conv.ask(i18n.__('DATE', moment().format('LL')));
});
exports.demoAction = functions.https.onRequest(app);
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-09-04 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-09-04 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eUtilize the locale string from user requests to tailor responses for different regions.\u003c/p\u003e\n"],["\u003cp\u003eLeverage third-party libraries like i18n-node and moment.js to manage localized strings and date/time formats.\u003c/p\u003e\n"],["\u003cp\u003eCreate localized string resource files in JSON format for each supported locale.\u003c/p\u003e\n"],["\u003cp\u003eConfigure i18n-node and set the locale within your Cloud Function for Firebase using the user's locale.\u003c/p\u003e\n"],["\u003cp\u003eReturn localized responses by calling \u003ccode\u003eask()\u003c/code\u003e with strings generated from your resource files and libraries.\u003c/p\u003e\n"]]],[],null,["# Fulfillment (Dialogflow)\n\nYour fulfillment logic can use the locale string it receives in every request to\ncater responses to users. This guide shows you how to use some third-party\nlocalization libraries within a Cloud Function for Firebase to return\nlocalized responses.\n\nLocalization libraries\n----------------------\n\nHere are some helpful libraries to consider to help you\ngenerate customized responses for specific locales:\n\n- General purpose: [I18n-node](//github.com/mashpie/i18n-node) (our example code snippets use this library)\n- General purpose: [format.js](//formatjs.io/)\n- Timezone/time localization: [moment.js](//momentjs.com/) (our example code snippets use this library)\n- Money/currency: [numeral.js](//numeraljs.com/)\n\nCreate localized responses\n--------------------------\n\nThis section shows you how to create localized string resource files that\ncontain localized strings and how to use these resource files in your Cloud\nFunction for Firebase fulfillment.\n\nTo create localized responses:\n\n1. In the same directory as your `package.json` and `index.js` files, create a `locales` directory for your localized string files. We'll refer to this directory as `\u003cproject-dir\u003e/functions/locales`.\n2. Create a resource file that contains localized strings for every locale that\n you want to support. For example, if you want to support `en-US`, `en-GB`,\n and `de-DE` locales with localized welcome and date messages, those files\n might look like this:\n\n **`\u003cproject-dir\u003e/functions/locales/en-US.json`** \n\n {\n \"WELCOME_BASIC\": \"Hello, welcome!\",\n \"DATE\": \"The date is %s\"\n }\n\n **`\u003cproject-dir\u003e/functions/locales/en-GB.json`** \n\n {\n \"WELCOME_BASIC\": \"Hello, welcome!\",\n \"DATE\": \"The date is %s\"\n }\n\n **`\u003cproject-dir\u003e/functions/locales/de-DE.json`** \n\n {\n \"WELCOME_BASIC\": \"Hallo und willkommen!\",\n \"DATE\": \"Das Datum ist %s\"\n }\n\n3. In the `package.json` file, declare the i18n-node and moment libraries as\n dependencies:\n\n {\n ...\n \"dependencies\": {\n \"actions-on-google\": \"^2.7.0\",\n \"firebase-admin\": \"^7.2.1\",\n \"firebase-functions\": \"^2.2.1\",\n \"i18n\": \"^0.8.3\",\n \"moment\": \"^2.22.1\"\n }\n }\n\n4. In the `index.js` file, declare the dependencies for the i18n-node and moment\n libraries:\n\n ```gdscript\n const i18n = require('i18n');\n const moment = require('moment');\n ```\n\n \u003cbr /\u003e\n\n5. In the `index.js` file, configure the i18n-node with your supported locales:\n\n ```css+lasso\n i18n.configure({\n locales: ['en-US', 'en-GB', 'de-DE'],\n directory: __dirname + '/locales',\n defaultLocale: 'en-US'\n });\n ```\n\n \u003cbr /\u003e\n\n6. Set the locale for the libraries using `conv.user.locale` from the client library\n property.\n\n ```text\n app.middleware((conv) =\u003e {\n i18n.setLocale(conv.user.locale);\n moment.locale(conv.user.locale);\n });\n ```\n\n \u003cbr /\u003e\n\n7. To return a localized response, call `ask()` with a localized string\n returned by i18n. This snippet also contains a function that uses moment\n to return a localized date:\n\n ```scdoc\n app.intent('Default Welcome Intent', (conv) =\u003e { // must not be async for i18n\n conv.ask(i18n.__('WELCOME_BASIC'));\n });\n\n app.intent('date', (conv) =\u003e { // must not be async for i18n\n conv.ask(i18n.__('DATE', moment().format('LL')));\n });\n ```\n\n \u003cbr /\u003e\n\nHere's a complete index.js file as an example: \n\n```gdscript\n'use strict';\nconst {dialogflow} = require('actions-on-google');\nconst functions = require('firebase-functions');\nconst i18n = require('i18n');\nconst moment = require('moment');\n\ni18n.configure({\n locales: ['en-US', 'en-GB', 'de-DE'],\n directory: __dirname + '/locales',\n defaultLocale: 'en-US'\n});\n\nconst app = dialogflow({debug: true});\n\napp.middleware((conv) =\u003e {\n i18n.setLocale(conv.user.locale);\n moment.locale(conv.user.locale);\n});\n\napp.intent('Default Welcome Intent', (conv) =\u003e { // must not be async for i18n\n conv.ask(i18n.__('WELCOME_BASIC'));\n});\n\napp.intent('date', (conv) =\u003e { // must not be async for i18n\n conv.ask(i18n.__('DATE', moment().format('LL')));\n});\n\nexports.demoAction = functions.https.onRequest(app);\n```\n\n\u003cbr /\u003e"]]