@@ -34,6 +34,28 @@ function get_workspaces_from_app_name(app_name) {
3434 if ( app . length > 0 ) return app [ 0 ] . workspaces ;
3535}
3636
37+ function get_workspaces_plural_text ( count ) {
38+ // Pluralization rule: n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2
39+ // 0: 1, 21, 31... (singular)
40+ // 1: 2-4, 22-24... (few)
41+ // 2: 5-20, 25-30... (many)
42+ let plural_form = 2 ; // default
43+ if ( count % 10 == 1 && count % 100 != 11 ) {
44+ plural_form = 0 ;
45+ } else if ( count % 10 >= 2 && count % 10 <= 4 && ( count % 100 < 10 || count % 100 >= 20 ) ) {
46+ plural_form = 1 ;
47+ }
48+
49+ // Use context for plural forms
50+ if ( plural_form === 0 ) {
51+ return __ ( "Workspace" , null , "plural_single" ) ;
52+ }
53+ if ( plural_form === 1 ) {
54+ return __ ( "Workspaces" , null , "plural_few" ) ;
55+ }
56+ return __ ( "Workspaces" , null , "plural_many" ) ;
57+ }
58+
3759function get_route ( desktop_icon ) {
3860 let route ;
3961 if ( ! desktop_icon ) return ;
@@ -82,7 +104,7 @@ function save_desktop() {
82104 `${ frappe . session . user } :desktop` ,
83105 JSON . stringify ( frappe . boot . desktop_icons )
84106 ) ;
85- frappe . toast ( "Desktop Saved" ) ;
107+ frappe . toast ( __ ( "Desktop Saved" ) ) ;
86108 frappe . pages [ "desktop" ] . desktop_page . update ( ) ;
87109}
88110
@@ -166,25 +188,25 @@ class DesktopPage {
166188 let menu_items = [
167189 {
168190 icon : "edit" ,
169- label : "Edit Profile" ,
191+ label : __ ( "Edit Profile" ) ,
170192 url : `/update-profile/${ frappe . session . user } ` ,
171193 } ,
172194 {
173195 icon : "lock" ,
174- label : "Reset Password" ,
196+ label : __ ( "Reset Password" ) ,
175197 url : "/update-password" ,
176198 } ,
177199 {
178200 icon : "rotate-ccw" ,
179- label : "Reset to Default" ,
201+ label : __ ( "Reset to Default" ) ,
180202 onClick : function ( ) {
181203 reset_to_default ( ) ;
182204 window . location . reload ( ) ;
183205 } ,
184206 } ,
185207 {
186208 icon : "log-out" ,
187- label : "Logout" ,
209+ label : __ ( "Logout" ) ,
188210 onClick : function ( ) {
189211 frappe . app . logout ( ) ;
190212 } ,
@@ -447,7 +469,8 @@ class DesktopIconGrid {
447469 pull : true ,
448470 } ,
449471 setData : function ( /** DataTransfer */ dataTransfer , /** HTMLElement*/ dragEl ) {
450- let title = $ ( dragEl ) . find ( ".icon-title" ) . text ( ) ;
472+ let titleElement = $ ( dragEl ) . find ( ".icon-title" ) ;
473+ let title = titleElement . attr ( "data-original-label" ) || titleElement . text ( ) ;
451474 let icon = me . icons . find ( ( d ) => {
452475 return d . icon_title === title ;
453476 } ) ;
@@ -465,7 +488,8 @@ class DesktopIconGrid {
465488 } else {
466489 let from = $ ( evt . from . parentElement ) ;
467490 let to = $ ( evt . to . parentElement ) ;
468- let title = $ ( evt . item ) . find ( ".icon-title" ) . text ( ) ;
491+ let titleElement = $ ( evt . item ) . find ( ".icon-title" ) ;
492+ let title = titleElement . attr ( "data-original-label" ) || titleElement . text ( ) ;
469493 let selected_icon = get_desktop_icon_by_label ( title ) ;
470494 if ( $ ( to . get ( 0 ) . parentElement ) ) {
471495 me . reorder_icons ( me . sortable . toArray ( ) ) ;
@@ -477,7 +501,7 @@ class DesktopIconGrid {
477501 }
478502 }
479503 } else {
480- frappe . toast ( "Nothing changed" ) ;
504+ frappe . toast ( __ ( "Nothing changed" ) ) ;
481505 }
482506 save_desktop ( ) ;
483507 } ,
@@ -553,8 +577,10 @@ class DesktopIcon {
553577 modal . show ( ) ;
554578 } ) ;
555579 if ( this . icon_type == "App" ) {
580+ let count = this . child_icons . length ;
581+ let plural_text = get_workspaces_plural_text ( count ) ;
556582 $ ( $ ( this . icon_caption_area ) . children ( ) [ 1 ] ) . html (
557- `${ this . child_icons . length } Workspaces `
583+ `${ count } ${ plural_text } `
558584 ) ;
559585 }
560586 } else {
@@ -566,7 +592,7 @@ class DesktopIcon {
566592 if ( me . icon_data . sidebar == "My Workspaces" ) {
567593 let sidebar_name = me . icon_data . sidebar . toLowerCase ( ) ;
568594 if ( frappe . boot . workspace_sidebar_item [ sidebar_name ] . items . length == 0 ) {
569- frappe . toast ( "No Private Workspaces for user" ) ;
595+ frappe . toast ( __ ( "No Private Workspaces for user" ) ) ;
570596 } else {
571597 let workspace_name =
572598 frappe . boot . workspace_sidebar_item [ sidebar_name ] . items [ 0 ] [ "link_to" ] ;
@@ -648,15 +674,16 @@ class DesktopModal {
648674 } ) ;
649675 }
650676 make_modal ( icon_title ) {
677+ const translated_title = __ ( icon_title ) ;
651678 if ( $ ( ".desktop-modal" ) . length == 0 ) {
652- this . modal = new frappe . get_modal ( icon_title , "" ) ;
679+ this . modal = new frappe . get_modal ( translated_title , "" ) ;
653680 this . modal . find ( ".modal-header" ) . addClass ( "desktop-modal-heading" ) ;
654681 this . modal . addClass ( "desktop-modal" ) ;
655682 this . modal . find ( ".modal-dialog" ) . attr ( "id" , "desktop-modal" ) ;
656683 this . modal . find ( ".modal-body" ) . addClass ( "desktop-modal-body" ) ;
657684 this . $child_icons_wrapper = this . modal . find ( ".desktop-modal-body" ) ;
658685 } else {
659- this . modal . find ( ".modal-title" ) . text ( icon_title ) ;
686+ this . modal . find ( ".modal-title" ) . text ( translated_title ) ;
660687 $ ( this . modal . find ( ".modal-body" ) ) . empty ( ) ;
661688 if ( frappe . desktop_utils . modal_stack . length == 1 ) {
662689 this . title_section . find ( ".icon" ) . remove ( ) ;
0 commit comments