-
Notifications
You must be signed in to change notification settings - Fork 133
feat: add language to community #663
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
base: main
Are you sure you want to change the base?
Changes from all commits
94a67cd
e9ecbf5
4fa2a75
ade9e36
30ea630
cff978f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |
| } from './messages'; | ||
| import { CommunityContext } from './communityContext'; | ||
| import * as commAdmin from './scenes.communityAdmin'; | ||
| import { isValidLanguage } from '../../../util/languages'; | ||
|
|
||
| const CURRENCIES = parseInt(process.env.COMMUNITY_CURRENCIES || '10'); | ||
|
|
||
|
|
@@ -25,6 +26,7 @@ export const communityWizard = new Scenes.WizardScene<CommunityContext>( | |
|
|
||
| const { | ||
| name, | ||
| language, | ||
| currencies, | ||
| group, | ||
| channels, | ||
|
|
@@ -61,6 +63,7 @@ export const communityWizard = new Scenes.WizardScene<CommunityContext>( | |
| } | ||
|
|
||
| if (undefined === name) return createCommunitySteps.name(ctx); | ||
| if (undefined === language) return createCommunitySteps.language(ctx); | ||
| if (undefined === currencies) return createCommunitySteps.currencies(ctx); | ||
| if (undefined === group) return createCommunitySteps.group(ctx); | ||
| if (undefined === channels) return createCommunitySteps.channels(ctx); | ||
|
|
@@ -71,6 +74,7 @@ export const communityWizard = new Scenes.WizardScene<CommunityContext>( | |
|
|
||
| const community = new Community({ | ||
| name, | ||
| language, | ||
| currencies, | ||
| group, | ||
| order_channels: channels, | ||
|
|
@@ -150,6 +154,38 @@ const createCommunitySteps = { | |
|
|
||
| return ctx.wizard.next(); | ||
| }, | ||
| async language(ctx: CommunityContext) { | ||
| const prompt = await createCommunityPrompts.language(ctx); | ||
|
|
||
| ctx.wizard.state.handler = async (ctx: CommunityContext) => { | ||
| const text = ctx?.message?.text; | ||
| if (!text) { | ||
| await ctx.deleteMessage(); | ||
| return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); | ||
| } | ||
|
|
||
| ctx.wizard.state.error = null; | ||
| const lang = text.trim().toLowerCase(); | ||
|
|
||
| if (!isValidLanguage(lang)) { | ||
| ctx.telegram.deleteMessage(ctx.chat!.id, ctx.message!.message_id); | ||
| ctx.wizard.state.error = ctx.i18n.t( | ||
| 'wizard_community_invalid_language', | ||
| ); | ||
| return await ctx.wizard.state.updateUI(); | ||
| } | ||
|
|
||
| ctx.wizard.state.language = lang; | ||
| await ctx.wizard.state.updateUI(); | ||
| await ctx.telegram.deleteMessage( | ||
| ctx.message!.chat.id, | ||
| ctx.message!.message_id, | ||
| ); | ||
| return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); | ||
| }; | ||
|
|
||
| return ctx.wizard.next(); | ||
| }, | ||
| async currencies(ctx: CommunityContext) { | ||
| const prompt = await createCommunityPrompts.currencies(ctx); | ||
|
|
||
|
|
@@ -427,6 +463,9 @@ const createCommunityPrompts = { | |
| async name(ctx: CommunityContext) { | ||
| return ctx.reply(ctx.i18n.t('wizard_community_enter_name')); | ||
| }, | ||
| async language(ctx: CommunityContext) { | ||
| return ctx.reply(ctx.i18n.t('wizard_community_enter_language')); | ||
| }, | ||
| async currencies(ctx: CommunityContext) { | ||
| return ctx.reply(ctx.i18n.t('wizard_community_enter_currency')); | ||
| }, | ||
|
|
@@ -837,6 +876,46 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( | |
| }, | ||
| ); | ||
|
|
||
| export const updateLanguageCommunityWizard = new Scenes.WizardScene( | ||
| 'UPDATE_LANGUAGE_COMMUNITY_WIZARD_SCENE_ID', | ||
| async (ctx: CommunityContext) => { | ||
| try { | ||
| const { community } = ctx.wizard.state; | ||
| let message = | ||
| ctx.i18n.t('language') + ': ' + (community.language || 'en') + '\n\n'; | ||
| message += ctx.i18n.t('wizard_community_enter_language') + '\n\n'; | ||
| message += ctx.i18n.t('wizard_to_exit'); | ||
| await ctx.reply(message); | ||
|
|
||
| return ctx.wizard.next(); | ||
| } catch (error) { | ||
| logger.error(error); | ||
| ctx.scene.leave(); | ||
| } | ||
| }, | ||
| async (ctx: CommunityContext) => { | ||
| try { | ||
| if (ctx.message === undefined) return ctx.scene.leave(); | ||
|
|
||
| const lang = ctx.message.text.trim().toLowerCase(); | ||
| if (!isValidLanguage(lang)) { | ||
| ctx.deleteMessage(); | ||
| return await ctx.reply(ctx.i18n.t('wizard_community_invalid_language')); | ||
| } | ||
|
|
||
| const { community } = ctx.wizard.state; | ||
| community.language = lang; | ||
| await community.save(); | ||
| await ctx.reply(ctx.i18n.t('operation_successful')); | ||
|
|
||
| return ctx.scene.leave(); | ||
| } catch (error) { | ||
| logger.error(error); | ||
| ctx.scene.leave(); | ||
| } | ||
| }, | ||
| ); | ||
|
Comment on lines
+879
to
+917
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Locate locale files and check for the 'language' key
# First, find all locale files
echo "=== Finding locale files ==="
find . -type f \( -name "*.yaml" -o -name "*.yml" \) | grep -i locale | head -20
echo ""
echo "=== Checking for 'language' key in locale files ==="
# Check for language key in YAML files
for file in locales/*.yaml locales/*.yml 2>/dev/null; do
if [ -f "$file" ]; then
echo "File: $file"
if grep -q "^language\s*:" "$file" 2>/dev/null; then
echo " ✓ 'language' key found"
else
echo " ✗ 'language' key NOT found"
fi
fi
doneRepository: lnp2pBot/bot Length of output: 480 🏁 Script executed: #!/bin/bash
# Check for isValidLanguage function and examine the scenes file
echo "=== Locating isValidLanguage function ==="
rg "isValidLanguage" -A 5 -B 2
echo ""
echo "=== Examining updateLanguageCommunityWizard context ==="
# Check the file structure around the wizard
rg "updateLanguageCommunityWizard" -B 5 -A 40Repository: lnp2pBot/bot Length of output: 8734 🏁 Script executed: #!/bin/bash
# Find i18n configuration
echo "=== Searching for i18n configuration ==="
rg "new TelegrafI18n" -A 5 -B 2
echo ""
echo "=== Checking if locales/en.yaml contains 'language' key ==="
head -100 locales/en.yaml | grep -n "language"
echo ""
echo "=== Counting lines and structure of en.yaml ==="
wc -l locales/en.yaml
head -30 locales/en.yamlRepository: lnp2pBot/bot Length of output: 2631 🏁 Script executed: #!/bin/bash
# Search more thoroughly for i18n configuration
echo "=== Searching for i18n instantiation (various patterns) ==="
rg "i18n\s*=" -A 3 -B 2 | head -50
echo ""
echo "=== Searching for 'language' key in ALL locale files ==="
for locale in locales/*.yaml; do
if grep -q "^language:" "$locale" 2>/dev/null; then
echo "✓ $(basename $locale): has 'language' key at root level"
else
# Try with spaces
if grep -q "^\s*language:" "$locale" 2>/dev/null; then
echo "✓ $(basename $locale): has 'language' key (with indent)"
else
echo "✗ $(basename $locale): NO 'language' key found"
fi
fi
done
echo ""
echo "=== Checking en.yaml for 'language' anywhere ==="
rg "language" locales/en.yamlRepository: lnp2pBot/bot Length of output: 1733 🏁 Script executed: #!/bin/bash
# Confirm the exact structure of the 'language' key in en.yaml
echo "=== Exact context of 'language' key in en.yaml ==="
rg -A 2 -B 2 "^language:" locales/en.yaml
echo ""
echo "=== Checking all keys used in updateLanguageCommunityWizard ==="
echo "Looking for: 'language', 'wizard_community_enter_language', 'wizard_to_exit', 'operation_successful'"
echo ""
for key in "language" "wizard_community_enter_language" "wizard_to_exit" "operation_successful"; do
echo "Key: $key"
for locale in locales/*.yaml; do
if rg -q "^[[:space:]]*$key:" "$locale" 2>/dev/null; then
echo " ✓ $(basename $locale): exists"
else
echo " ✗ $(basename $locale): MISSING"
fi
done
echo ""
doneRepository: lnp2pBot/bot Length of output: 1481 Add 'language' key to non-English locale files to complete translations. Line 885 uses Add 🤖 Prompt for AI Agents |
||
|
|
||
| export const addEarningsInvoiceWizard = new Scenes.WizardScene( | ||
| 'ADD_EARNINGS_INVOICE_WIZARD_SCENE_ID', | ||
| async (ctx: CommunityContext) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.