2 * Copyright 2003, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
4 * Copyright 2012, John Scipione, jscipione@gmail.com
5 * All rights reserved. Distributed under the terms of the MIT License.
12 #include <LocaleRoster.h>
15 BLocale::BLocale(const BLanguage
* language
,
16 const BFormattingConventions
* conventions
)
18 if (conventions
!= NULL
)
19 fConventions
= *conventions
;
21 BLocale::Default()->GetFormattingConventions(&fConventions
);
24 fLanguage
= *language
;
26 BLocale::Default()->GetLanguage(&fLanguage
);
30 BLocale::BLocale(const BLocale
& other
)
32 fConventions(other
.fConventions
),
33 fLanguage(other
.fLanguage
)
38 /*static*/ const BLocale
*
41 return BLocaleRoster::Default()->GetDefaultLocale();
46 BLocale::operator=(const BLocale
& other
)
51 BAutolock
lock(fLock
);
52 BAutolock
otherLock(other
.fLock
);
53 if (!lock
.IsLocked() || !otherLock
.IsLocked())
56 fConventions
= other
.fConventions
;
57 fLanguage
= other
.fLanguage
;
69 BLocale::GetCollator(BCollator
* collator
) const
74 BAutolock
lock(fLock
);
78 *collator
= fCollator
;
85 BLocale::GetLanguage(BLanguage
* language
) const
90 BAutolock
lock(fLock
);
94 *language
= fLanguage
;
101 BLocale::GetFormattingConventions(BFormattingConventions
* conventions
) const
106 BAutolock
lock(fLock
);
107 if (!lock
.IsLocked())
110 *conventions
= fConventions
;
117 BLocale::GetString(uint32 id
) const
119 // Note: this code assumes a certain order of the string bases
121 BAutolock
lock(fLock
);
122 if (!lock
.IsLocked())
125 if (id
>= B_OTHER_STRINGS_BASE
) {
131 return fLanguage
.GetString(id
);
136 BLocale::SetFormattingConventions(const BFormattingConventions
& conventions
)
138 BAutolock
lock(fLock
);
139 if (!lock
.IsLocked())
142 fConventions
= conventions
;
147 BLocale::SetCollator(const BCollator
& newCollator
)
149 BAutolock
lock(fLock
);
150 if (!lock
.IsLocked())
153 fCollator
= newCollator
;
158 BLocale::SetLanguage(const BLanguage
& newLanguage
)
160 BAutolock
lock(fLock
);
161 if (!lock
.IsLocked())
164 fLanguage
= newLanguage
;