Skip to content

Commit

Permalink
feat(l10n): translate category list in price add form depending on us…
Browse files Browse the repository at this point in the history
…er locale (#275)
  • Loading branch information
raphodn committed Feb 4, 2024
1 parent 7bed8b9 commit f821b75
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ function prettyRelativeDateTime(dateTimeString, size=null) {
diff < 60 && "just now" || diff < 120 && "1 minute ago" || diff < 3600 && Math.floor(diff / 60) + " minutes ago" || diff < 7200 && "1 hour ago" || diff < 86400 && Math.floor(diff / 3600) + " hours ago") || day_diff == 1 && "Yesterday" || day_diff < 10 && day_diff + " days ago" || Math.ceil(day_diff / 7) + " weeks ago";
}

function getCategory(categoryId) {
return CategoryTags.find(ct => ct.id === categoryId)
function getLocaleCategoryTags(locale) {
return import(`./data/categories/${locale}.json`)
}

function getCountryEmojiFromName(countryString) {
Expand Down Expand Up @@ -144,7 +144,7 @@ export default {
prettyDate,
prettyDateTime,
prettyRelativeDateTime,
getCategory,
getLocaleCategoryTags,
getCountryEmojiFromName,
getLocationTitle,
}
13 changes: 10 additions & 3 deletions src/views/AddPriceMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export default {
{key: 'category', value: this.$t('AddPriceSingle.ProductModeList.Category'), icon: 'mdi-basket-outline'}
],
productMode: null,
categoryTags: CategoryTags, // list of category tags for autocomplete
categoryTags: null, // list of category tags for autocomplete // see initPriceMultipleForm
originsTags: OriginsTags, // list of origins tags for autocomplete
labelsTags: LabelsTags,
barcodeScanner: false,
Expand Down Expand Up @@ -435,10 +435,17 @@ export default {
},
mounted() {
this.initPriceMultipleForm()
this.proofType = this.$route.path.endsWith('/receipt') ? 'RECEIPT' : 'PRICE_TAG'
},
methods: {
initPriceMultipleForm() {
/**
* init form config (product mode, categories, last locations)
* (init form done in initNewProductPriceForm)
*/
this.proofType = this.$route.path.endsWith('/receipt') ? 'RECEIPT' : 'PRICE_TAG'
utils.getLocaleCategoryTags(this.appStore.user.language.code).then((module) => {
this.categoryTags = module.default
})
if (this.recentLocations.length) {
this.setLocationData(this.recentLocations[0])
}
Expand Down Expand Up @@ -529,10 +536,10 @@ export default {
this.product = null
},
initNewProductPriceForm() {
this.productMode = this.appStore.user.last_product_mode_used
this.clearProductPriceForm()
this.productPriceForm = JSON.parse(JSON.stringify(this.productPriceNew))
this.productPriceForm.currency = this.appStore.user.last_currency_used
this.productMode = this.appStore.user.last_product_mode_used
this.productPriceForm.price_per = this.categoryPricePerList[0].key // init to 'KILOGRAM' because it's the most common use-case
},
createPrice() {
Expand Down
13 changes: 8 additions & 5 deletions src/views/AddPriceSingle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ import ProductCard from '../components/ProductCard.vue'
import BarcodeScanner from '../components/BarcodeScanner.vue'
import BarcodeManualInput from '../components/BarcodeManualInput.vue'
import LocationSelector from '../components/LocationSelector.vue'
import CategoryTags from '../data/category-tags.json'
import OriginsTags from '../data/origins-tags.json'
import LabelsTags from '../data/labels-tags.json'
Expand Down Expand Up @@ -304,7 +303,7 @@ export default {
{key: 'category', value: this.$t('AddPriceSingle.ProductModeList.Category'), icon: 'mdi-basket-outline'}
],
productMode: null, // 'barcode' or 'category' // see initPriceSingleForm
categoryTags: CategoryTags, // list of category tags for autocomplete
categoryTags: null, // list of category tags for autocomplete // see initPriceSingleForm
originsTags: OriginsTags, // list of origins tags for autocomplete
labelsTags: LabelsTags,
barcodeScanner: false,
Expand Down Expand Up @@ -374,14 +373,18 @@ export default {
},
initPriceSingleForm() {
/**
* init product mode, currency & last location
* init form config (product mode, categories, last locations)
* init form
*/
this.productMode = this.addPriceSingleForm.product_code ? 'barcode' : this.appStore.user.last_product_mode_used
this.addPriceSingleForm.price_per = this.categoryPricePerList[0].key // init to 'KILOGRAM' because it's the most common use-case
this.addPriceSingleForm.currency = this.appStore.user.last_currency_used
utils.getLocaleCategoryTags(this.appStore.user.language.code).then((module) => {
this.categoryTags = module.default
})
if (this.recentLocations.length) {
this.setLocationData(this.recentLocations[0])
}
this.addPriceSingleForm.price_per = this.categoryPricePerList[0].key // init to 'KILOGRAM' because it's the most common use-case
this.addPriceSingleForm.currency = this.appStore.user.last_currency_used
},
clearProof() {
this.proofImage = null
Expand Down

0 comments on commit f821b75

Please sign in to comment.