Преглед изворни кода

日历组件多语言适配

xiaohaizhao пре 1 година
родитељ
комит
604ae3afbc

+ 12 - 3
components/wx-calendar/index.js

@@ -138,6 +138,11 @@ Component({
                 }
             })
         })
+        getApp().globalData.Language.getLanguagePackage(this)
+        this.setData({
+            languagecode: wx.getStorageSync('languagecode')
+        })
+        console.log("language",this.data.language)
     },
     methods: {
         initialize(current, callback) {
@@ -742,11 +747,15 @@ Component({
         setTitleInfo(d, today = null) {
             today = today ? today : this.data._today
             let titleInfo = this.data.titleInfo
+            const count = this.getDateDiff(new Date(today.year, today.month - 1, today.day), new Date(d.year, d.month - 1, d.day))
             if (d.year == today.year && d.month == today.month && d.day == today.day) {
-                titleInfo = this._curr_view == 2 ? `第${ YearWeekOrder(today.year, today.month, today.day) }周  ${ today.week_name }` : today.week_name
+                    titleInfo = this._curr_view == 2 ? `第${ YearWeekOrder(today.year, today.month, today.day) }周  ${ today.week_name }` : today.week_name
             } else {
-                const count = this.getDateDiff(new Date(today.year, today.month - 1, today.day), new Date(d.year, d.month - 1, d.day))
-                titleInfo = `${ this._curr_view == 2 ? '第' + YearWeekOrder(d.year, d.month, d.day) + '周  ' : ''}${ Math.abs(count) }天${ count < 0 ? '前' : '后' }`
+                    titleInfo = `${ this._curr_view == 2 ? '第' + YearWeekOrder(d.year, d.month, d.day) + '周  ' : ''}${ Math.abs(count) }天${ count < 0 ? '前' : '后' }`
+            }
+            if(wx.getStorageSync('languagecode')!='ZH') {
+                titleInfo = count < 0 ?`${ Math.abs(count) } days ago`: `After ${ Math.abs(count) } days`
+                if(count==0) titleInfo = 'today'
             }
             this.setData({ titleInfo })
         },

+ 10 - 10
components/wx-calendar/index.wxml

@@ -15,23 +15,23 @@
         data-min="{{ minHeight }}">
         <view class="wd-calendar-bar">
             <view class="wd-calendar-title" data-info="{{ titleInfo }}" bindtap="{{ calendar_wxs.handleYearPanelShow }}">
-                <text >{{ months[currTab].year }}</text><text class="wd-calendar-title-cn">年</text>
+                <text >{{ months[currTab].year }}</text><text class="wd-calendar-title-cn">{{language['']?',':'年'}}</text>
                 <text >{{ months[currTab].month }}</text>
-                <text class="wd-calendar-title-cn">月</text>
+                <text class="wd-calendar-title-cn">{{language['']?'':'月'}}</text>
             </view>
             <view class="wd-calendar-options">
                 <view class="wd-calendar-option">
                     <view class="wd-calendar-option-it ">
                         <view class="wd-calendar-option-views today {{ tdOpShow ? 'show' : '' }}" catchtap="toToday">
-                            <view class="wd-calendar-option-view">今</view>
+                            <view class="wd-calendar-option-view">{{language['现在']||''}}</view>
                         </view>
                     </view>
                 </view>
                 <view class="wd-calendar-option">
                     <view class="wd-calendar-option-it">
                         <view class="wd-calendar-option-views" catchtap="{{ calendar_wxs.toggleView }}">
-                            <view catchtransitionend="handleOpBarTransEnd" class="wd-calendar-option-view {{ (currView == 1 || currView == 3)? 'curr' : '' }}">月</view>
-                            <view catchtransitionend="handleOpBarTransEnd" class="wd-calendar-option-view {{ currView == 2 ? 'curr' : '' }}">周</view>
+                            <view catchtransitionend="handleOpBarTransEnd" class="wd-calendar-option-view {{ (currView == 1 || currView == 3)? 'curr' : '' }}">{{language['']||'月'}}</view>
+                            <view catchtransitionend="handleOpBarTransEnd" class="wd-calendar-option-view {{ currView == 2 ? 'curr' : '' }}">{{language['']||'周'}}</view>
                             <view class="wd-calendar-option-view-bar" style="transform: translateX({{ currView == 2 ? '70rpx' : 0 }}) translateZ(0px);"></view>
                         </view>
                     </view>
@@ -39,7 +39,7 @@
             </view>
         </view>
         <view class="wd-calendar-week-bar">
-            <view class="wd-calendar-week-item" wx:for="{{ Weeks }}">{{ item }}</view>
+            <view class="wd-calendar-week-item" wx:for="{{ Weeks }}">{{language['周' + item] || item}}</view>
         </view>
         <view 
             class="wd-calendar-month-body {{ solidDay ? '' : 'solid' }}" 
@@ -92,7 +92,7 @@
                                     <text 
                                         wx:if="{{ d.marker && d.marker.holiday.length > 0 }}"
                                         style="color: {{ d.marker.corner[0].color ? d.marker.corner[0].color : '#2a97ff' }};">{{ d.marker.holiday[0].mark }}</text>
-                                    <text wx:else>{{ d.lunar_day }}</text>
+                                    <text wx:elif="{{languagecode == 'ZH'}}">{{d.lunar_day}}</text>
                                     <view class="wd-calendar-schedules" wx:if="{{ d.marker && d.marker.schedule.length > 0 }}">
                                         <view 
                                             class="wd-calendar-schedule"
@@ -123,8 +123,8 @@
 
         <view class="wd-calendar-years-panel {{ yearPanelShow ? 'show' : '' }}">
             <view class="wd-calendar-bar">
-                <view class="wd-calendar-title show ym" data-info="{{ yearMs[currYmTab].lunar_year }}">
-                    <text >{{ yearMs[currYmTab].year }}</text><text class="wd-calendar-title-cn margin-left">年</text>
+                <view class="wd-calendar-title show ym" data-info="{{languagecode=='ZH' ? yearMs[currYmTab].lunar_year : '' }}">
+                    <text >{{ yearMs[currYmTab].year }}</text><text wx:if="{{languagecode=='ZH'}}" class="wd-calendar-title-cn margin-left">年</text>
                 </view>
             </view>
             <view class="wd-calendar-years-panel-body">
@@ -152,7 +152,7 @@
                                     data-month="{{ year.months[mrdx * 4 + mdx].month }}">
                                     <view class="wd-calendar-ym-month-contaner">
                                         <view class="wd-calendar-ym-m-r">
-                                            <view class="wd-calendar-ym-m">{{ year.months[mrdx * 4 + mdx].month }}</view>
+                                            <view class="wd-calendar-ym-m {{languagecode=='ZH'?'':'wd-calendar-ym-m-EN'}}">{{ year.months[mrdx * 4 + mdx].month }}</view>
                                         </view> 
                                         <view wx:for="{{ year.months[mrdx * 4 + mdx].lunar }}" wx:for-item="l" wx:for-index="idx" class="wd-calendar-ym-l" >
                                             <view class="wd-calendar-ym-l-i"><text data-order="{{ l.order }}">{{ l.day }}</text></view>

+ 9 - 0
components/wx-calendar/index.wxss

@@ -718,6 +718,15 @@ text {
     color: inherit;
 }
 
+.wd-calendar-ym-m-EN::after {
+    content: "Month";
+    position: relative;
+    font-size: 20rpx;
+    font-weight: normal;
+    margin-left: 4rpx;
+    color: inherit;
+}
+
 .wd-calendar-ym-l {
     font-size: 20rpx;
     line-height: 20rpx;

+ 7 - 0
project.private.config.json

@@ -8,6 +8,13 @@
     "condition": {
         "miniprogram": {
             "list": [
+                {
+                    "name": "签到",
+                    "pathName": "packageA/clockIn/index",
+                    "query": "",
+                    "launchMode": "default",
+                    "scene": null
+                },
                 {
                     "name": "找回密码",
                     "pathName": "pages/login/retrievePassword",